Guest User

Untitled

a guest
Mar 13th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1.     protected $_saltLength = 50;
  2.     protected $_saltChars = 'qwertyuiopasdfghjklzxcvbnm1234567890QWERTYUIOPASDFGHJKLZXCVBNM,.#!%*()-+=';
  3.    
  4.     /**
  5.      * Hash the password and set the salt
  6.      *
  7.      * @see Model::beforeSave()
  8.      */
  9.     public function beforeSave()
  10.     {
  11.        
  12.         if (isset($this->data['Member']['password']))
  13.         {
  14.             $salt = $this->_generateSalt();
  15.             $this->data['Member']['salt'] = $salt;
  16.             $this->data['Member']['password'] = sha1($salt . $this->data['Member']['password']);
  17.             $this->data['Member']['status'] = self::STATUS_ACTIVE;
  18.         }
  19.        
  20.         return true;
  21.        
  22.     }
  23.    
  24.     protected function _generateSalt()
  25.     {
  26.        
  27.         for ($i = 0; $i < $this->_saltLength; $i++)
  28.         {
  29.             $str .= $this->_saltChars[rand(0, $this->_saltLength - 1)];
  30.         }
  31.        
  32.         return $str;
  33.        
  34.     }
  35.    
  36. }
Add Comment
Please, Sign In to add comment