0
我正在嘗試創建一個簡單的密碼重置功能,允許管理員更改用戶密碼並通過電子郵件向他們發送新密碼。除了密碼以外,一切都可以在數據庫中實際改變。我發現了很多關於這個主題的信息,但沒有任何工作。爲什麼密碼未被更改?我使用CakePHP 2.1在cakephp中更改密碼2x
我嘗試這樣做:
public function auto_reset_password($id = null){
$this->User->id = $id;
$randomPass= $this->User->generatePassword();
$randomPassHashed= $this->Auth->password($randomPass);
$this->User->set('password', $randomPassHashed);
$this->User->save();
//email code....
}
而代這樣的:
$u = $this->User->find('first', array(
'conditions' => array('User.id' => $id)
));
//.....
$u['User']['password'] = $randomPassHashed;
我的用戶模式有這個beforeSave:
public function beforeSave() {
if (isset($this->data[$this->alias]['password'])) {
$this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
}
return true;
}
儘量避免哈希它兩次(你在這裏通過手動哈希調用和通過beforeSave()回調)。這可能也有幫助:[在CakePHP中使用密碼](http://www.dereuromark.de/2011/08/25/working-with-passwords-in-cakephp/) – mark
添加UserModel,所以我們可以採取看看。 –
我擺脫了第一次密碼哈希,並設置密碼與unhashhed值,但沒有任何改變......你在用戶模型中尋找什麼?我無法在該文件中找到與此相關的任何其他代碼。生成密碼功能絕對有效。 – Cbas