2012-01-01 4 views
0

CakePHP 2.0 응용 프로그램에 로그인하려고하는데 로그인 오류가 발생합니다.암호 해시 및 AuthComponent

:이 가지고있는 관점에서

// Users Model 
public function beforeSave ($options = array()) { 
    $this->data['User']['password'] = AuthComponent::password($this->data['User']['password']); 
    return true; 
} 

// Users Controller 
public $components = array ('Acl', 'Session', 
    'Auth' => array (
    'authenticate' => array (
     // login e logout sono di default i seguenti controller e views 
     // 'loginRedirect' => array ('controller' => 'users', 'action' => 'login'), 
     // 'logoutRedirect' => array ('controller' => 'users', 'action' => 'logout'), 
     'Form' => array (
      'fields' => array (
      // il valore default 
       'username' => 'email' 
      ), 
      'scope' => array (
       'User.active' => 1 
      ) 
     ) 
    ), 
    'authError' => 'Login error message I get' 
)); 

public function login() { 
    if ($this->request->is('post')) { // if the request came from post data and not via http (useful for security) 
     // the password is hashed in User Model in beforeSave method as read on documentation 
     // debug ($this->data); 
     if ($this->Auth->login()) { 
      $id = $this->Auth->user('id'); 
      return $this->redirect(array('controller'=>'users', 'action'=>$id, $this->Auth->user('username'))); 
     } else { 
      $this->Session->setFlash('Login error message', 'default', array(), 'auth'); 
     } 
    } 
} 

: 공식 documentation 내가 암호를 해시,하지만 난 여전히 로그인 오류를 얻는 방법을 읽은 tutorial에서 은, 여기에 내가 그것을 어떻게입니다 내가 데이터를 디버깅하려고하면

// the view login.ctp 
echo $this->Form->text('User.email', array('id'=>'email', 'value'=>'[email protected]')); 
echo $this->Form->password('User.password', array('id'=>'password', 'value'=>'password')); 

나는이 얻을 :

// in the controller 
debug($this->data); 
// in the view 
Array 
(
    [User] => Array 
    (
     [email] => [email protected] 
     [password] => thepass // not hashed 
    ) 
) 

난 항상 Login error message를 얻을 수 있기 때문에이 로그인 할 수 없습니다. 어떻게 해결할 수 있습니까?

답변

0

상표,

(1) 어떤 오류 메시지가 표시됩니까?

(2) 단지 기록을 위해 레이아웃에서 sessionFlash가 인쇄되었는지 확인하십시오!

echo $this->Layout->sessionFlash(); 

(3) 인증 구성 요소를 어떻게 설정 했습니까? 예를 들어, 내 AppController가에서 나는이 방법을 설정 한 :

public $components = array(
    'Session', 
    'Cookie', 
    'Acl', 
    /** 
    * Default is authorize option is ActionsAuthorize. 
    * In this case, system uses AclComponent to check for permissions on an action level. 
    * learn more: http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#authorization 
    */ 
    'Auth'=> array(
     'authorize' => array(
      'Actions' => array('actionPath' => 'controllers') 
     ), 
     'authenticate' => array(
      'Form' => array(
       'fields' => array('username' => 'email', 'password' => 'password') 
      ) 
     ) 
    ) 
); 

(4) 마지막으로, 저는 믿습니다 (확인해야합니다) 수동 해시 암호 로그인을 수행 할 필요가 없습니다. 최소한 올바른 설정을 한 후에이 코드는 나를 위해 작동합니다.

if ($this->request->is('post')) { 
     if ($this->Auth->login()) { 
      // recirect stuffs 
+0

감사합니다. 1) 질문에서 오류를 업데이트했습니다. | 2) sessionFlash를 인쇄하려고하면 다음과 같은 오류가 발생합니다. 치명적 오류 : /public_html/site.com/app/View/Layouts/default.ctp의 비 객체에서 sessionFlash() 멤버 함수를 호출합니다. 3) 나는 이것을 보게 될 것이다! thanks – vitto

+0

(2) 컨트롤러 나 AppController에서'$ helpers' 배열의 도우미'Layout'을 설정했는지 확인하십시오. 'public $ helpers = array (/ * others * /, 'Layout',/* others * /)'; – colares

+0

어쩌면 당신이 말하는거야 :''? php echo $ this-> Session-> flash(); echo $ this-> Session-> flash ('auth'); ?>'이 함수는 에러를 내기 위해 사용한다. – vitto