note 33452 added to function.crypt

From: Date: Thu, 26 Jun 2003 13:40:03 +0000
Subject: note 33452 added to function.crypt
Groups: php.notes 
Request: Send a blank email to php-notes+get-51040@lists.php.net to get a copy of this message
If your server only supports simple DES-based encryption, and you want to encrypt passwords with the MD5 algorithm and use a random salt, you may use the following function: function crypt_md5($str, $salt=null) { if (!$salt) $salt = md5(uniqid(rand(), 1)); $salt = substr($salt, 0, 8); return $salt . ":" . md5($salt . $str); } It can be used similarly to the crypt() function, i.e.: $crypted_pass = crypt_md5($password); if (crypt_md5($verified_pass, $crypted_pass) == $crypted_pass) { // correct password } Note that this function does not generate the same result as crypt() with the MD5 support. ---- Manual Page -- http://www.php.net/manual/en/function.crypt.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33452 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33452&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33452&report=yes

« previous php.notes (#51040) next »