2014-07-19 2 views
0

사용자를 편집하려고하면 로그인 양식이 표시됩니다. 로그인하려고하면 '사용자 이름 및/또는 비밀번호가 잘못되었습니다'라는 메시지가 나타납니다. UsersController. 사용자 이름과 암호가 맞더라도. cakePHP : 사용자의 편집 페이지로 이동하려면 로그인 할 수 없습니다.

내 사용자 테이블 :

1 user_id bigint(11) AUTO_INCREMENT 
2 user_username varchar(45) utf8_general_ci 
3 user_email varchar(255) utf8_general_ci 
4 user_password varchar(255) utf8_general_ci 
5 user_image varchar(255) utf8_general_ci 
6 user_created timestamp CURRENT_TIMESTAMP 
7 user_modified timestamp 
8 user_deleted timestamp 
9 user_lastlogin timestamp 
10 user_locked timestamp    
11 user_confirmed timestamp  
12 person_id bigint(20) 

이 내 사용자 모델에 있습니다

public function beforeSave($options=array()){ 
    parent::beforeSave(); 
    if (!empty($this->data['User']['user_password'])){ 
     $this->data['User']['user_password'] = Security::hash($this->data['User']['user_password'], 'sha256', true); 
    } 
    return true; 
} 

이 내의 AppController에 있습니다

public $components = array(
    'DebugKit.Toolbar', 
    'Session', 
    'Auth' => array(
     'authenticate' => array(
     'Form' => array(
      'fields' => array(
       'username' => 'user_username', 
       'password' => 'user_password' 
      ), 
      'passwordHasher' => array(
       'className' => 'Simple', 
       'hashType' => 'sha256' 
      ) 
     ) 
    ), 
     'loginRedirect' => array('controller'=>'users', 'action'=>'index'), 
     'logoutRedirect' => array('controller'=>'users', 'action'=>'index'), 
     'AuthError' => 'You cannot access that page', 
     'authorize'=>array('Controller') 
    ) 
); 

public function isAuthorized($user){ 
    return true; 
} 

public function beforeFilter() { 
    $this->Auth->allow('index', 'view'); 
} 

이 내 login.ctp

echo $this->Form->create(); 
echo $this->Form->input('user_username'); 
echo $this->Form->input('user_password', array('type'=>'password')); 
echo $this->Form->end('Submit'); 
01 23,516,

이 내 UsersController에 : 나는이에 잠시 동안 찾아 봤는데

public function beforeFilter(){ 
    parent::beforeFilter(); 
    $this->Auth->allow('add'); 
} 

public function login(){ 
    if ($this->request->is('post')){ 
     if($this->Auth->login()){ 
     $this->redirect($this->Auth->redirect()); 
     } else { 
      $this->Session->setFlash(_('The username and/or password is incorrect')); 
     } 
     } 
} 

public function logout(){ 
    $this->redirect($this->Auth->logout()); 
} 

. user_password의 이름을 password로 변경하고 Type을 변경하고 varchar (255)를 (40)으로 변경하면 아무 것도 해결되지 않는 것 같습니다. 어쩌면 해싱과 관련이 있을지 모르지만 나는 그 일을 제대로 수행했다고 생각합니다.

IIS와 함께 일하고 있습니다. 일종의 구성이 필요합니까?

나를 도와 줄 사람이 있습니까?

답변

1

'username'및 'password'필드는 임의로 지정할 필요가 없습니다. 또한 AuthComponent :: password는 2.4부터 사용되지 않습니다. 당신의 AuthComponent 구성에서 다음과 같은 매개 변수를 추가 할 수 있습니다 :

public $components = array(
    'Auth' => array(
     'authenticate' => array(
      'Form' => array(
       'fields' => array(
        'username' => 'user_username', 
        'password' => 'user_password' 
       ), 
       'passwordHasher' => array(
        'className' => 'Simple', 
        'hashType' => 'sha256' 
       ) 
      ) 
     ) 
    ) 
); 

당신의 인증 모델에서 :

public function beforeSave($options = array()) { 
    parent::beforeSave(); 
    if (!empty($this->data['Model']['password'])) { 
     $this->data['Model']['password'] = Security::hash($this->data['Model']['password'], 'sha256', true); 
    } 
    return true; 
} 
+0

http://book.cakephp.org/2.0/en/core-libraries/components/ authentication.html – andtxr

+0

원본 답변을 새로 작성하는 대신 편집 할 수 있습니다. – ndm

+0

상기시켜 주셔서 감사합니다. ;) – andtxr

0

분명히 사용자 이름으로 데이터베이스의 user_username을 변경해야합니다.

2 user_username varchar(45) utf8_general_ci 
4 user_password varchar(255) utf8_general_ci 

에 :

그래서 나는 변경

2 username varchar(45) utf8_general_ci 
4 password varchar(255) utf8_general_ci 

또한 내 CakePHP의 프로젝트에서 그 둘을 바 꾸었습니다.

그러나 나는 당신이 암호와 사용자 이름을 변경할 수 있는지 궁금해합니다. 그것은 cakePHP에서 Auth를 사용하기위한 기본값입니까?

관련 문제