note 40226 added to function.sha1
| From: | brian_bisaillon at rogers dot com | Date: | Thu, 26 Feb 2004 01:19:36 +0000 |
| Subject: | note 40226 added to function.sha1 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65765@lists.php.net to get a copy of this message | ||
Source code to create SSHA passwords...
public function HashPassword($password)
{
mt_srand((double)microtime()*1000000);
$salt = mhash_keygen_s2k(MHASH_SHA1, $password, substr(pack('h*', md5(mt_rand())), 0,
8), 4);
$hash = "{SSHA}".base64_encode(mhash(MHASH_SHA1, $password.$salt).$salt);
return $hash;
}
Source code to validate SSHA passwords...
public function ValidatePassword($password, $hash)
{
$hash = base64_decode(substr($hash, 6));
$original_hash = substr($hash, 0, 20);
$salt = substr($hash, 20);
$new_hash = mhash(MHASH_SHA1, $password . $salt);
if (strcmp($original_hash, $new_hash) == 0)
... do something because your password is valid ...
else
echo 'Unauthorized: Authorization has been refused for the credentials you provided. Please
login with a valid username and password.';
... be sure to clear your session data ...
}
Note: The format is compatible with OpenLDAP's SSHA scheme if I'm not mistaken.
----
Manual Page -- http://www.php.net/manual/en/function.sha1.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+40226
Delete -- http://master.php.net/manage/user-notes.php?action=delete+40226&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+40226&report=yes
Search -- http://master.php.net/manage/user-notes.php