我在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