我正在使用CakePHP 3.0开发,并想要比较“更改密码”功能中表单中输入的旧密码与数据库密码。但是因为密码已经被哈希加密,所以即使使用相同密码进行哈希加密,得到的哈希密码每次也不一样,导致我无法完成这个功能。
请帮助我解决这个问题。
提前感谢, Melee
请帮助我解决这个问题。
提前感谢, Melee
$validator
->notEmpty('current_password')
->add('current_password', 'custom', [
'rule' =>
function($value, $context) {
$query = $this->find()
->where([
'id' => $context['data']['id']
])
->first();
$data = $query->toArray();
return (new DefaultPasswordHasher)->check($value, $data['password']);
},
'message' => 'Current password is incorrect!'
]);