Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cakephp比较Web服务的密码_Php_Web Services_Authentication_Cakephp_Cakephp 2.6 - Fatal编程技术网

cakephp比较Web服务的密码

cakephp比较Web服务的密码,php,web-services,authentication,cakephp,cakephp-2.6,Php,Web Services,Authentication,Cakephp,Cakephp 2.6,我是cakephp新手,我正在实现一个更新密码的web服务,其中用户将提供oldpassword、newpassword、username参数,我必须在db中检查用户名是否有旧密码,然后用newpassword更新db 到目前为止,我所做的是,我得到了参数,我可以用这样的用户名获取数据 $username = $this->request->query['username']; $oldpassword = $this->request->query['oldpass

我是cakephp新手,我正在实现一个更新密码的web服务,其中用户将提供oldpassword、newpassword、username参数,我必须在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);


?>
现在它返回数据,但如果我像这样使用密码字段

 $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);


?>
它返回空结果,即使我通过了正确的旧密码。。!
在我出错的地方,非常感谢您的帮助……

好吧,我假设您使用的是默认密码哈希程序

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

如果是这样的话,你可以像这样得到散列密码

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

数据库中的密码是加密的。用户输入的密码为纯文本。您必须首先加密旧密码才能正确比较。我如何才能做到这一点?我是说哪种加密?我是cakephpI的新手,我认为这个方法是Security::hash。好的,我需要你的帮助,我从配置文件中知道这两件事,“Security.salt”和“Security.cipherSeed”,我现在如何加密普通密码?你能为你提供
CakePHP
版本和你的应用程序的
Auth
配置吗?我接受你的答案,因为它与我找到的解决方案非常相似。实际上我正在做一个已经部分实施的项目。他们已经将blowfishpassword哈希器用于cakephp。您可以在这里看到,我使用BlowfishPasswordHasher的check()方法得到了解决方案。谢谢。我已经实现了与您提到的完全相同的方法。