note 45350 added to function.crypt
| From: | thorhajo at gmail dot com | Date: | Thu, 02 Sep 2004 22:34:10 +0000 |
| Subject: | note 45350 added to function.crypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-75963@lists.php.net to get a copy of this message | ||
Here's a little function I wrote to generate MD5 password hashes in the format they're
found in /etc/shadow:
function shadow($password)
{
$hash = '';
for($i=0;$i<8;$i++)
{
$j = mt_rand(0,53);
if($j<26)$hash .= chr(rand(65,90));
else if($j<52)$hash .= chr(rand(97,122));
else if($j<53)$hash .= '.';
else $hash .= '/';
}
return crypt($password,'$1$'.$hash.'$');
}
I've written this so that each character in the a-zA-Z./ set has a 1/54 of a chance of being
selected (26 + 26 + 2 = 54), thus being statistically even.
----
Manual Page -- http://www.php.net/manual/en/function.crypt.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45350
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45350&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45350&report=yes
Search -- http://master.php.net/manage/user-notes.php