【发布时间】:2011-10-13 12:28:49
【问题描述】:
在我的密码重置页面上,我使用 Security::hash() 保存了用户的新密码。但是,当我尝试登录时,我的数据库保存的哈希密码与 Auth 在对登录字段中的输入进行哈希处理时提供的版本不匹配。
我假设这类似于 Security::hash() 使用我的应用程序盐来散列密码,而 Auth 不使用该盐?
你是怎么做的?
【问题讨论】:
标签: cakephp passwords authentication
在我的密码重置页面上,我使用 Security::hash() 保存了用户的新密码。但是,当我尝试登录时,我的数据库保存的哈希密码与 Auth 在对登录字段中的输入进行哈希处理时提供的版本不匹配。
我假设这类似于 Security::hash() 使用我的应用程序盐来散列密码,而 Auth 不使用该盐?
你是怎么做的?
【问题讨论】:
标签: cakephp passwords authentication
您是否尝试过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() 方法。
应该是Security::hash($password, 'sha1', true)
您可以将第二个参数保留为 NULL,因为 Auth 使用与 Security 中指定的相同的哈希。
【讨论】: