note 107338 added to function.crypt
| From: | ircmaxell@php.net | Date: | Wed, 01 Feb 2012 14:38:15 +0000 |
| Subject: | note 107338 added to function.crypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-185817@lists.php.net to get a copy of this message | ||
Harry at simans:
That's absolutely not necessary. Crypt will automatically peel off the salt for you (and
include it in the output). You can add a function to generate the salt for you, but the crypt
function works the same way your wrapper does:
<?php
function makeSalt() {
static $seed = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
$algo = '$2a';
$strength = '$08';
$salt = '$';
for ($i = 0; $i < 22; $i++) {
$salt .= substr($seed, mt_rand(0, 63), 1);
}
return $algo . $strength . $salt;
}
function makeHash($password) {
return crypt($password, makeSalt());
}
function verifyHash($password, $hash) {
return $hash == crypt($password, $hash);
}
?>
Which then means that this relation will always hold:
<?php
true === verifyHash($password, makeHash($password));
?>
So there's no need to store the salt separately, since crypt() stores it inline for you...
----
Server IP: 208.69.120.55
Probable Submitter: 64.210.199.232
----
Manual Page -- http://www.php.net/manual/en/function.crypt.php
Edit -- https://master.php.net/note/edit/107338
Del: integrated -- https://master.php.net/note/delete/107338/integrated
Del: useless -- https://master.php.net/note/delete/107338/useless
Del: bad code -- https://master.php.net/note/delete/107338/bad+code
Del: spam -- https://master.php.net/note/delete/107338/spam
Del: non-english -- https://master.php.net/note/delete/107338/non-english
Del: in docs -- https://master.php.net/note/delete/107338/in+docs
Del: other reasons-- https://master.php.net/note/delete/107338
Reject -- https://master.php.net/note/reject/107338
Search -- https://master.php.net/manage/user-notes.php