2014-09-27 274 views
0

Auth返回false。散列的密碼與數據庫中的散列密碼匹配,但仍返回false。Cakephp 2.5.2 Auth始終返回false

這裏是模型:

App::uses('AppModel', 'Model'); 

    class User extends AppModel { 

    public $validate = array(
    'username' => array(
     'notEmpty' => array(
      'rule' => array('notEmpty'), 
      //'message' => 'Your custom message here', 
      //'allowEmpty' => false, 
      //'required' => false, 
      //'last' => false, // Stop validation after this rule 
      //'on' => 'create', // Limit validation to 'create' or 'update' operations 
     ), 
     ), 
     'password' => array(
      'notEmpty' => array(
      'rule' => array('notEmpty'), 
      //'message' => 'Your custom message here', 
      //'allowEmpty' => false, 
      //'required' => false, 
      //'last' => false, // Stop validation after this rule 
      //'on' => 'create', // Limit validation to 'create' or 'update' operations 
     ), 
     ), 
     ); 
     public function beforeSave($options = array()) { 
    if (isset($this->data[$this->alias]['password'])) { 

     $this->data[$this->alias]['password'] =AuthComponent::password($this->data[$this->alias]['password']); 

     ; 
    } 
    return true; 



} 
     } 

這裏是AppController中:

 class AppController extends Controller { 


     public $components = array(
     'Session', 
     'Auth' => array(
     'authenticate' => array(
      'Form' => array(

      ) 
     ), 
     'loginAction'=>array(
      'controller'=>'users', 
      'action'=>'login' 
     ), 
     'loginRedirect' => array(
      'controller' => 'references', 
      'action' => 'admin_index' 
     ), 
     'logoutRedirect' => array(
      'controller' => 'home', 
      'action' => 'index', 
      'home' 
     ) 

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

    } 

這裏是UsersController:

  public function login(){ 

     var_dump($this->Auth->login());die; 
     if ($this->request->is('post')) { 
     if ($this->Auth->login()) { 

      return $this->redirect(array('controller'=>'references', 'action'=>'admin_index')); 

     } 

     $this->Session->setFlash(__('Invalid username or password, try again')); 
     } 
     } 

和視圖:

  <div class="users form"> 
     <?php echo $this->Session->flash('auth'); ?> 
     <?php echo $this->Form->create('User',array('action'=>'login')); ?> 
      <fieldset> 
     <legend> 
     <?php echo __('Please enter your username and password'); ?> 
     </legend> 
     <?php echo $this->Form->input('username'); 
     echo $this->Form->input('password'); 
     ?> 
     </fieldset> 
     <?php echo $this->Form->end(__('Login')); ?> 
     </div> 

我已經嘗試過使用BlowFish,但它不工作,所以我創建用戶時切換到Auth默認散列和哈希,然後登錄匹配,因此散列工作正常。我沒有得到什麼問題,所以請幫助。

回答

0

半小時後我再次嘗試,現在它的工作。誰知道問題是什麼。無論如何,如果您在上面的代碼中發現任何問題,請閱讀併發布答案。謝謝!