我在CakePHP 1.3应用程序中具有以下功能,它需要一个令牌并允许用户更改其密码。一切似乎工作正常,但密码实际上并没有改变:/任何想法是什么问题?CakePHP密码重置不更改密码
function admin_changepassword ($token = null)
{
// If has a token or form has been submitted
if (!empty($token) || !(empty($this->data)))
{
$user = $this->User->find('first',array("MD5(User.email + '".Configure::read('Security.salt')."')"=>$token));
if (empty($user))
{
$this->redirect(array('admin'=>false,'controller'=>'pages','action'=>'display','home'));
$this->Session->setFlash('Invalid token');
}
else
{
$this->set('user',$user);
if (!empty($this->data['User']['password']))
{
$user['User']['password'] = $this->data['User']['password'];
$this->User->save($this->data);
$this->Session->setFlash('Your password has been changed! Please log in.');
$this->redirect(array('admin'=>true,'controller' => 'users', 'action' => 'login'));
}
}
}
else
{
$this->redirect(array('admin'=>false,'controller'=>'home','action'=>'display','home'));
$this->Session->setFlash('No token');
}
}
你问你的数据库凑每个用户的每一个密码与查询,潜在的一个巨大的无用的动作比较。 – deceze
你能否进一步解释这一点,因为我不明白,并且密码没有被更改的原因? – Cameron
您正在查询WHERE MD5(密码...)='somestring''。这意味着数据库需要在每一行执行'MD5(password ...)',以便将它与'somestring'进行比较。无论如何,这个标记应该是什么?我不认为这是你的问题。 *你的问题究竟是什么?它有什么作用? – deceze