Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.68 KB | None | 0 0
  1. private function process_password($password, $salt = '') {
  2.     /**
  3.      * Process a password to encrypt it for storage or verification.
  4.      * @param string - plain text password for processing.
  5.      * @access private
  6.      * @return array Containing the encrypted password and the salt.
  7.      */
  8.  
  9.     //Check if the salt has been supplied. If not, generate one.
  10.     if ($salt && strlen($salt) !== 64) {
  11.         log_message('info', 'Supplied password to process_password() was not the correct 64-byte length.');
  12.         return false;
  13.     }
  14.     $salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
  15.  
  16.     $hashed_password = hash('sha256', $password . $salt);
  17.  
  18.     return array('password' => $hashed_password, 'salt' => $salt);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement