我是CakePHP的新手旧密码,然后使用newPassword更新DB。
到目前为止我所做的是,我得到了参数,我可以像这样的用户名获取数据
$username = $this->request->query['username'];
$oldpassword = $this->request->query['oldpassword'];
$dataexist = $this->User->find('first', array('fields' => array('User.id','User.username','User.password'), 'conditions' => array('User.username' => $username)));
现在返回数据,但是如果我使用这样的密码字段
$dataexist = $this->User->find('first', array('fields' => array('User.id','User.username','User.password'), 'conditions' => array('User.username' => $username,'User.password' => $oldpassword)));
它返回空的结果,即使我传递了正确的旧密码。我在做错的地方,任何帮助都非常感谢...
好吧,我在这里假设您正在使用默认密码hasher,
共享您的验证配置以更改该假设:)
如果是这样,您可以获取这样的哈希密码
<?php
App::uses('SimplePasswordHasher', 'Controller/Component/Auth');
$passwordHasher = new SimplePasswordHasher();
$hashPassword = $passwordHasher->hash($rawPassword);
?>
您可以使用我的代码:
$newPass = '123abc';
$user = $this->User->find('first', array(
'conditions' => array(
'User.id' => AuthComponent::user('id')
),
'fields' => array('password')
));
$storedHash = $user['User']['password'];
$newHash = Security::hash($newPass, 'blowfish', $storedHash);
if($storedHash == $newHash){
return true;
}else{
return false;
}