【发布时间】:2015-08-06 20:29:51
【问题描述】:
我正在使用 cakephp 3.0.3,我正在编写更改用户密码的操作, 为此,我想将当前密码(由用户输入)与数据库中的现有密码进行比较。 但它每次都会给我不同的哈希值,
这是我在用户实体中的密码设置器,
protected function _setPassword($password)
{
return (new DefaultPasswordHasher)->hash($password);
}
在控制器中,
public function changePassword()
{
$this->request->data['current_password'] = '123456';
$user = $this->Users->get(5); //get entity of userId 5
$existing = $user->password; //display password of user 5 from database
$user->password = $this->request->data['current_password'];
$new = $user->password;
}
输出:
'$2y$10$inROlYu/ZKfowe.tTfX48OQ1q4oQBIzq3khzH5.jjITYjAxE3eMtm' //output of $existing, which is 123456 in plain
'$2y$10$A8zHGjCs/G1mlbfpzb6oIuc7TgjqC0ExR6X79kjt.1r64GSTSjpXy' //output of $new
这里两个密码相同,但我得到了差异。每次按 F5(刷新页面)时散列。
那么有什么方法可以比较两个密码并在 cakephp 3.0.3 中将其更改为新密码?
【问题讨论】:
标签: cakephp authentication passwords cakephp-3.0