这是我第一次在
PHP中使用crypt()函数,我无法弄清楚它为什么不起作用.我的代码基于这篇文章:
http://www.techrepublic.com/blog/australia/securing-passwords-with-blowfish/1274
function blowfishHash ($pw) {
//generate random salt
$salt = "$2y$10$";
for ($i = 0; $i < 22; $i++) {
$salt .= substr("./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", mt_rand(0, 63), 1);
}
$hash = crypt($pw, $salt);
//printout to file
$file = fopen("debug.txt", "w+");
fwrite($file, "\n\n\n".$pw);
fwrite($file, "\n\n\n".$salt);
fwrite($file, "\n\n\n".$hash);
fclose($file);
return $hash;
}
我使用示例密码“password”调用了该函数.
产生的盐是:$2y $10 $NzRQNjTRfP4jXKvb4TCO.G
但密码是“$2mV0NZp92R3g” – 这似乎太短了.
有人可以帮我弄清楚我做错了什么吗?