这是我第一次在 PHP 中使用 crypt() 函数,我不明白为什么它不起作用。我的代码基于这篇文章:http://www.techrepublic.com/blog/australia/secure-passwords-with-blowfish/1274 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"
——这似乎太短了。
有人可以帮我弄清楚我做错了什么吗?
正如您在评论中所述,您正在使用 PHP 5.2.x。
Blowfish 实现仅在 PHP >= 5.3.x 中可用。如果由于任何原因无法安装较新的 PHP 版本,您可以检查here https://stackoverflow.com/questions/11637445/to-use-crypt-blowfish-on-php-5-2-that-doesnt-support-it有关如何使 Blowfish 与较旧的 PHP 版本一起工作的更多信息。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)