繁体   English   中英

cakephp比较Web服务的密码

[英]cakephp compare password for webservice

我是Cakephp的新手,我正在实现一个用于更新密码的Web服务,其中用户将提供oldpassword,newpassword,用户名参数,我必须在db中检查该用户名是否具有旧密码,然后使用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)));

返回空结果,即使我通过正确的旧密码..! 我在哪里做错了,非常感谢您的帮助...

好吧,我在这里假设您使用的是默认密码哈希尔,

分享您的身份验证配置以更改该假设:)

如果是这样,您可以像这样获得哈希密码

<?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;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM