note 68200 deleted from function.sha1 by nlopess
| From: | nlopess@php.net | Date: | Tue, 18 Jul 2006 10:15:16 +0000 |
| Subject: | note 68200 deleted from function.sha1 by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-114873@lists.php.net to get a copy of this message | ||
Note Submitter: daniel dot esquivias at gmail dot com
Reason: useless
----
//REQUIRES MHASH LIBRARY (php_mhash.dll)
function hash_SSHA($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;
}
function validate_SSHA($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){
return 1;
} else {
return 0;
}
}
$thisvar = hash_SSHA("string");
if(validate_SSHA("string",$thisvar){
//valid, continue
} else {
//error
}