我有一个PHP版本低于5.5的服务器,我正在尝试使用Symfony中的bcrypt对用户身份验证进行编程。所以我安装了ircmaxwell/password-compat,但由于某种原因,编码器总是返回false。我所做的是:
$factory = $this->get('security.encoder_factory');
$encoder = $factory->getEncoder($user);
$encoded = $encoder->encodePassword('test', $user->getSalt());
die($encoded);
$encoded始终为空。我检查了一下,ircmaxwell中的密码.php被调用,它在此行中返回一个false:
if (!is_string($ret) || PasswordCompat'binary'_strlen($ret) != $resultLength) {
return false;
}
因为字符串的长度是 13,但结果长度是 60。我对bcrypt和这些东西了解不多,所以我只是不明白为什么会发生这种情况。谁能给我一个提示,为什么这不起作用?
提前谢谢。
事实证明我没有看到显而易见的。密码兼容库在要求下明确指出它需要 php>= 5.3.7。好吧,事实证明我的php版本是5.3.3.,所以难怪它不起作用。由于更新服务器不是一种选择,我将放弃 bcrypt 并使用其他东西。