note 102278 added to function.crypt
| From: | kaminski at istori dot com | Date: | Sat, 05 Feb 2011 23:43:47 +0000 |
| Subject: | note 102278 added to function.crypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176709@lists.php.net to get a copy of this message | ||
Here is an expression to generate pseudorandom salt for the CRYPT_BLOWFISH hash type:
<?php $salt = substr(str_replace('+', '.', base64_encode(pack('N4',
mt_rand(), mt_rand(), mt_rand(), mt_rand()))), 0, 22); ?>
It is intended for use on systems where mt_getrandmax() == 2147483647.
The salt created will be 128 bits in length, padded to 132 bits and then expressed in 22 base64
characters. (CRYPT_BLOWFISH only uses 128 bits for the salt, even though there are 132 bits in 22
base64 characters. If you examine the CRYPT_BLOWFISH input and output, you can see that it ignores
the last four bits on input, and sets them to zero on output.)
Note that the high-order bits of the four 32-bit dwords returned by mt_rand() will always be zero
(since mt_getrandmax == 2^31), so only 124 of the 128 bits will be pseudorandom. I found that
acceptable for my application.
----
Server IP: 69.147.83.197
Probable Submitter: 76.126.164.9
----
Manual Page -- http://www.php.net/manual/en/function.crypt.php
Edit -- https://master.php.net/note/edit/102278
Del: integrated -- https://master.php.net/note/delete/102278/integrated
Del: useless -- https://master.php.net/note/delete/102278/useless
Del: bad code -- https://master.php.net/note/delete/102278/bad+code
Del: spam -- https://master.php.net/note/delete/102278/spam
Del: non-english -- https://master.php.net/note/delete/102278/non-english
Del: in docs -- https://master.php.net/note/delete/102278/in+docs
Del: other reasons-- https://master.php.net/note/delete/102278
Reject -- https://master.php.net/note/reject/102278
Search -- https://master.php.net/manage/user-notes.php