note 105871 deleted from function.crypt by joey
| From: | joey@php.net | Date: | Sat, 19 May 2012 20:37:56 +0000 |
| Subject: | note 105871 deleted from function.crypt by joey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-188078@lists.php.net to get a copy of this message | ||
Note Submitter: eleljrk at gmail dot com
----
I've seen many CRYPT_BLOWFISH salt generators, but none REALLY go into the depth of it. This
give you a RANDOM string of 22 characters, the string can contain ANY OF THE ALLOWED characters for
the salt. I wont claim this the best solution, but this is fairly much everything you can do with a
random salt generator.
<?php
public function getSalt() {
$c = explode(" ", ". / a A b B c C d D e E f F g G h H i I j J k K l L m M n N o
O p P q Q r R s S t T u U v V w W x X y Y z Z 0 1 2 3 4 5 6 7 8 9");
$ks = array_rand($c, 22);
$s = "";
foreach($ks as $k) { $s .= $c[$k]; }
return $s;
}
?>
Take note that every allowed character is inside the $c variable, $s is the salt, $ks is for keys to
use in salt and $k is key. There is probably a better and shorter script out there, but this is
solid enough for me.
Have fun with the code.