【问题标题】:CakePHP - Auth hashed password different to Security::hash()CakePHP - 与 Security::hash() 不同的身份验证哈希密码
【发布时间】:2011-10-13 12:28:49
【问题描述】:

在我的密码重置页面上,我使用 Security::hash() 保存了用户的新密码。但是,当我尝试登录时,我的数据库保存的哈希密码与 Auth 在对登录字段中的输入进行哈希处理时提供的版本不匹配。

我假设这类似于 Security::hash() 使用我的应用程序盐来散列密码,而 Auth 不使用该盐?

你是怎么做的?

【问题讨论】:

    标签: cakephp passwords authentication


    【解决方案1】:

    您是否尝试过AuthComponent::password() 方法?

    此外,如果该字段名为 password,请检查 AuthComponent 是否尚未对其进行哈希处理。


    编辑:在 3.x 中,请参阅 DefaultPasswordHasher::hash(),如 Hashing Passwords 中所述。

    【讨论】:

    • 谢谢。这行得通,但是在模型中包含组件(我保存新密码的地方)是不好的做法吗?似乎我可以通过指定 Security::hash($password, 'sha1', Configure::read('Security.salt')) 让 Security 对密码进行与 Auth 相同的哈希处理,但同样这似乎是一种不好的做法,因为它不能确保哪个类在整个应用程序中进行密码哈希处理的一致性。
    • AuthComponent 已经加载,您可以从模型中静态调用上述方法。有关用法示例,请参阅此 old paste of mine,尽管我会推荐 this blog post 中的方法而不是我的 encryptPasswordField() 方法。
    【解决方案2】:

    应该是Security::hash($password, 'sha1', true)

    您可以将第二个参数保留为 NULL,因为 Auth 使用与 Security 中指定的相同的哈希。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-17
      • 1970-01-01
      • 1970-01-01
      • 2015-01-15
      • 2019-05-25
      • 2016-06-06
      • 2016-04-19
      相关资源
      最近更新 更多