PHP crypt()Blowfish函数不起作用 [英] PHP crypt() Blowfish Function Not Working

查看:95
本文介绍了PHP crypt()Blowfish函数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次在PHP中使用crypt()函数,但我不知道为什么它不起作用.我的代码基于这篇文章: http://www.techrepublic .com/blog/australia/securing-passwords-with-blowfish/1274

This is my first time using the crypt() function in PHP, and I can't figure out why it isn't working. My code is based on this article: 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"调用了该函数.

I called the function with the sample password "password".

所得盐为:$2y$10$NzRQNjTRfP4jXKvb4TCO.G
但是密码是"$2mV0NZp92R3g" –似乎太短了.

The resultant salt was: $2y$10$NzRQNjTRfP4jXKvb4TCO.G
But the password was "$2mV0NZp92R3g" – which seems far too short.

有人可以帮我弄清楚我在做什么错吗?

Could someone please help me figure out what I'm doing wrong?

推荐答案

如注释中所述,您正在使用PHP 5.2.x.

As you stated in your comment, you are using PHP 5.2.x.

Blowfish实现仅在PHP> = 5.3.x中可用.如果由于某种原因无法安装更新的PHP版本,则可以检查

The Blowfish implementation is only available in PHP >= 5.3.x. If for any reason it is not possible to install a newer PHP version, you could check here on more information on how to make Blowfish work with older PHP versions.

这篇关于PHP crypt()Blowfish函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆