cakephp 比较 web 服务的密码
cakephp compare password for webservice
我是 cakephp 的新手,我正在实现一个用于更新密码的 Web 服务,用户将在其中提供旧密码、新密码、用户名参数,如果该用户名有旧密码,我必须检查数据库,然后更新数据库使用新密码。
到目前为止我所做的是,我得到了参数,我可以像这样使用用户名获取数据
$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,
分享您的身份验证配置以更改该假设:)
如果是这样的话,你可以这样获取hash密码
<?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;
}
我是 cakephp 的新手,我正在实现一个用于更新密码的 Web 服务,用户将在其中提供旧密码、新密码、用户名参数,如果该用户名有旧密码,我必须检查数据库,然后更新数据库使用新密码。
到目前为止我所做的是,我得到了参数,我可以像这样使用用户名获取数据
$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,
分享您的身份验证配置以更改该假设:)
如果是这样的话,你可以这样获取hash密码
<?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;
}