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 : AdministratorController에서
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';
}
:
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
체크 됨. :) 그게 아니고. 고맙습니다. –