在cakePHP 2.4>中是用戶認證的新過程。CakePHP 2.4如何驗證用戶? (No PASSWORD)
在db表和模型中,我獲得了名爲「passwd」的密碼列,表單輸入與db列名稱相同。
因此,在用戶模式,我有:
if (isset($this->data[$this->alias]['passwd'])) {
$passwordHasher = new SimplePasswordHasher();
$this->data[$this->alias]['passwd'] = $passwordHasher->hash($this->data[$this->alias]['passwd']);
}
在用戶控制器我有
public function beforeFilter() {
parent::beforeFilter();
// Allow users to register and logout.
$this->Auth->allow('register','verify','login');
$this->Auth->authenticate = array(
'Form' => array(
'fields' => array('username' => 'email', 'password' => 'passwd'),
),
);
}
public function login() {
// accept only ajax post request
if ($this->request->is('ajax') && $this->request->is('post')) {
$tmpUser['User']['username'] = $this->request->data['User']['email'];
$tmpUser['User']['password'] = $this->request->data['User']['passwd'];
// try to login user
if ($this->Auth->login ($tmpUser)) {
echo('Login Successfull');
} else {
echo('Login Incorrect');
}
}
}
可惜我仍然無法成功登錄在SQL轉儲不可公佈。密碼(只有用戶名)。
我試圖找到一些有用的信息,但沒有發現任何工作。
所以我嘗試的文檔:
http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html
但仍然沒有運氣。
這裏有人有同樣的問題或有人誰有這個解決方案?
感謝您的任何幫助。
'$這個 - > Auth->登錄($ tmpUser)'=>你是誰不明白之間的()和($ VAR)差分編號14433。您並未試圖登錄,您始終將該人員登錄。請參閱文檔。甚至有關於這種差異的警告。 – mark
你覺得呢? http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#identifying-users-and-logging-them-in – redrom
是的,紅色的框。 – mark