我在使用AuthController的用戶登錄不同模型時遇到問題。CakePHP 2.2.0 - AuthComponent - 與用戶不同的模型 - 密碼始終不正確
這是管理員,而不是用戶表。
在我的管理模式,我有:
function beforeSave(){
if(isset($this->data['Administrator']['password']))
$this->data['Administrator']['password'] = AuthController::password($this->data['Administrator']['password']);
return true;
}
的AppController:
public $components = array(
'Session',
'Auth' => array(
'loginAction' => array('controller' => 'administrators', 'action' => 'login'),
'loginRedirect' => array('controller' => 'Home', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'Home', 'action' => 'index'),
'authError' => "You can't access that page.",
'authorize' => array('Controller')
)
);
public function beforeFilter(){
$this->Auth->userModel = 'Administrator';
}
在AdministratorController:
public function login(){
if($this->request->is('post')){
if($this->Auth->login()){
$this->redirect($this->Auth->redirect());
}
else{
$this->Session->setFlash('Your username/password combination was incorrect.');
}
}
}
public function logout(){
$this->redirect($this->Auth->logout());
}
public function beforeFilter(){
parent::beforeFilter();
}
,並查看:
<?php
echo $this->Form->create('Administrator', array('controller' => 'administrators', 'action' => 'login'));
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end('Login');
?>
我調試$ this-> request-> data ['Administrator'] ['password'],並且我得到了與數據庫中相同的散列。
我不知道爲什麼它總是說用戶名/密碼不正確。
你確定它在保存之前不會散列兩次嗎?它是哈希登錄領域的正確比較? – tyjkenn 2012-07-05 22:57:08
已檢查。 :) 這並不是說。謝謝。 – 2012-07-06 08:57:47