2015-01-09 75 views
0

沒有人可以給我一個提示,爲什麼我登錄不起作用?用戶添加到數據庫,但沒有辦法登錄cakePHP2.6.0

可以添加一個用戶,同時創建Blowfish密碼並將數據集保存到數據庫中,但我無法登錄。

模型

App::uses('AppModel', 'Model'); 
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth'); 
class Benutzer extends AppModel{ 
public $useTable = 'Benutzer'; 

public $validate = array(
    'username' => array(
     'required' => array(
      'rule' => array('notEmpty'), 
      'message' => 'benötigtes Feld' 
     ) 
    ), 
    'passwort' => array(
     'required' => array(
      'rule' => array('notEmpty'), 
      'message' => 'benötigtes Feld' 
     ) 
    ), 
    'rolle' => array(
     'valid' => array(
      'rule' => array('inList', array('admin', 'author', 'borrow', 'archive')), 
      'message' => 'Please enter a valid role', 
      'allowEmpty' => false) 
    ) 
); 


    public function beforeSave($options = array()) { 
    if (isset($this->data[$this->alias]['passwort'])) { 
     $passwordHasher = new BlowfishPasswordHasher(); 
     $this->data[$this->alias]['passwort'] = $passwordHasher->hash($this->data[$this->alias]['passwort']); 
    } 
    return true; 
} 

AppContorler

public $components = array(
         'DebugKit.Toolbar', 
         'Session', 
         'Paginator' => array(
          'className' => 'Bancha.BanchaPaginator'), 
         'Auth' => array(
          'loginRedirect' => array(
           'controller' => 'posts', 
           'action' => 'index' 
          ), 
          'logoutRedirect' => array(
           'controller' => 'pages', 
           'action' => 'display', 
           'home' 
          ), 
          'authenticate' => array(
           'Form' => array(
            'passwordHasher' => 'Blowfish' 
            ) 
          ), 
         ) 
        ); 

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

登錄

public function login() { 

      if ($this->request->is('post')) { 
       if ($this->Auth->login()) { 
        return $this->redirect($this->Auth->redirectUrl()); 
       } 
       $this->Session->setFlash(__('Invalid username or password, try again')); 
      } 

     } 

LOGIN CTP-文件

<div class="users form"> 
<?php echo $this->Session->flash('auth'); ?> 
<?php echo $this->Form->create('Benutzer'); ?> 
    <fieldset> 
     <legend> 
      <?php echo __('Please enter your username and password'); ?> 
     </legend> 
     <?php echo $this->Form->input('username', array('lable' => 'Username', 'type' => 'text'));?> 
     <?php echo $this->Form->input('passwort', array('lable' => 'Passwort', 'type' => 'password'));?> 
    </fieldset> 
<?php echo $this->Form->end(__('Login')); ?> 
</div> 
+0

什麼是數據庫中密碼的字段類型和長度? –

回答

0

問題是,我沒有定義'字段'

'authenticate' => array(
     'Form' => array(
     'fields' => array(
     'username' => 'username', //Default is 'username' in the userModel 
     'password' => 'passwort' //Default is 'password' in the userModel 
    ) 
相關問題