Symfony:ircmaxwell / password-compat - $ encoder-> encodePassword返回false

时间:2015-01-12 08:47:19

标签: php symfony bcrypt

我有一台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中的password.php被调用,它在这一行中返回false:

    if (!is_string($ret) || PasswordCompat\binary\_strlen($ret) != $resultLength) {
      return false;
    }

因为String的长度是13,但resultLength是60.我不太了解bcrypt和这些东西,所以我不明白为什么会这样。任何人都可以给我一个暗示,为什么这不起作用?

提前致谢。

1 个答案:

答案 0 :(得分:0)

原来我没有看到明显的。 password-compat库明确指出它需要php> = 5.3.7。 好吧,原来我的php版本是5.3.3。所以难怪它不起作用。 由于更新服务器不是一个选项,我将放弃bcrypt并使用其他东西。