【问题标题】:isPasswordValid does not work with sha256isPasswordValid 不适用于 sha256
【发布时间】:2019-09-11 14:49:24
【问题描述】:

我正在为现有的 oracle 数据库实现一个用户界面,其中用户表和密码存储为 sha256 哈希值。但是验证器显示密码错误。

配置:

security:
  encoders:
    App\Entity\User:
      algorithm: sha256

验证器功能:

public function checkCredentials($credentials, UserInterface $user)
{
    return $this->passwordEncoder->isPasswordValid($user, $credentials['password']); // -> False
    return hash_equals(hash('sha256', $credentials['password']), $user->getPassword()); // -> True
}

如上所述,如果我使用 hash_equals 手动检查密码,它可以工作。 有人可以帮忙吗?我认为可能是配置错误。

【问题讨论】:

  • 也许this post 可以帮忙?
  • 嗨 Magnus,它没有帮助,但下面 Alex 的回答是正确的方法。

标签: php symfony authentication


【解决方案1】:

sha256 不是此 YAML 设置的有效值。 Symfony 不(本机)支持像这样的直接哈希,因为它们被认为不够强大以用于密码。

如果你真的想使用 SHA256(你不应该),你可以create your own encoder

【讨论】:

  • 嗨,Alex,因为我必须使用现有数据库,所以我将编写自己的编码器。谢谢你。
猜你喜欢
  • 1970-01-01
  • 2014-07-21
  • 1970-01-01
  • 2018-04-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-12-25
相关资源
最近更新 更多