note 9026 deleted from function.crypt by jimw
| From: | jimw@php.net | Date: | Sat, 03 Nov 2001 18:17:51 +0000 |
| Subject: | note 9026 deleted from function.crypt by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-20371@lists.php.net to get a copy of this message | ||
I use the following function to generate my own salt, adopted from the Perl Cookbook. It generates
two-character salts but you can easily change it to suit your purpose.
As was mentioned in the User Notes for srand(), it's bad omen to seed repeatedly, so you might
want to remove the srand() line if your script is so written that you would have already seeded at
some point before calling the function.
function gensalt() {
srand((double)microtime()*1000000);
$saltseeds =
array('.','/','0','1','2','3','4','5','6','7','8','9',
'a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z',
'A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
return $saltseeds[rand(0,63)] . $saltseeds[rand(0,63)];
}
$password = 'blahblah';
$salt = gensalt();
$crypted = crypt($password,$salt);
echo "crypt('$password','$salt') is '$crypted'\n";