2013-02-23 52 views
1

登錄我的AppController:Auth->登錄()總是在用戶

public $components = array('Auth' => array(
    'authenticate' => array('Blowfish') 
), 

在我UsersController:

public function login() {  

if($this->request->isPost()) { 
     $this->autoRender = false; 
     if($this->Auth->login()) { 
      $this->response->statusCode(200); 
     } 
     else { 
      $this->response->statusCode(401); 
     } 
    } 

} 

而且不管數據發佈到/users/login的效應初探始終是200和用戶登錄。如何強制Auth不登錄,但在數據庫中檢查用戶名和密碼?

+0

你有什麼你的觀點裏面? – 2013-02-23 21:23:20

+0

請確保您遵循以下指示:http://book.cakephp.org/2.0/en/core-libraries/components/authentication.html#using-bcrypt-for-passwords – swiecki 2013-02-24 01:35:21

+0

您是否在'Auth - >允許()'在你之前的過濾器例如? – 2013-02-25 17:12:56

回答

0

我也有過河豚的煩惱。

但是,您是否記得更改密碼存儲在數據庫中的方式?

你不得不這樣做在你的「用戶」模式:

App::uses('Security', 'Utility'); 

class User extends AppModel { 

public function beforeSave($options = array()) { 
    // Use bcrypt 
    if (isset($this->data['User']['password'])) { 
     $hash = Security::hash($this->data['User']['password'], 'blowfish'); 
     $this->data['User']['password'] = $hash; 
    } 
    return true; 
} 

} 
相關問題