2017-02-07 19 views
-1

私はCakePHPの新人で、ログインビューの実装方法についてはtutorial on YouTubeを見ました。CakePHP 3.3 - 認証が機能しない

私はチュートリアルのステップバイステップを続けていましたが、$userは決して真実ではないようです。正しい資格情報でログインしようとしても、「不正なログイン」エラーが表示されます。

私の間違いはどこですか? UsersController.phpユーザーモデルに

$this->loadComponent('Auth', [ 
      'authenticate' => [ 
       'Form' => [ 
        'fields' => [ 
         'username' => 'email', 
         'password' => 'password' 
        ] 
       ] 
      ], 
      'loginAction' => [ 
       'controller' => 'Users', 
       'action' => 'login' 
      ] 
     ]); 

ログインフォーム

<br> 
<div class="index large-4 medium-4 large-offset-4 medium-offset-4 columns"> 
    <div class="panel"> 
     <h2 class="text-center"> 
      LOGIN 
     </h2> 
     <?= $this->Form->create(); ?> 
      <?= $this->Form->input('email'); ?> 
      <?= $this->Form->input('password', array('type' => 'password')); ?> 
      <?= $this->Form->submit('Login', array('class' => 'button')); ?> 
     <?= $this->Form->end(); ?> 
    </div> 
</div> 

_setPasswordのAppControllerでの認証を初期化

public function login() { 
    if ($this->request->is('post')) { 
     $user = $this->Auth->identify(); 
     if ($user) { 
      /* never gets here ****************/ 
      $this->Auth->setUser($user); 
      return $this->redirect(['controller' => 'posts']); 
     } 
     //Bad Login 
     $this->Flash->error('Incorrect Login'); 
    } 
} 

ログイン機能

protected function _setPassword($password) { 
    return (new DefaultPasswordHasher)->hash($this->$password); 
} 
+0

ユーザーが自分のパスワードが暗号化されていますが、確かではありますか? –

+0

はい、すべてのパスワードがハッシュされています。あなたは私に検索する正しい場所を示した。ありがとう! – mitch3ls

答えて

0

私は解決策を見つけた、私はハッシュ関数に$this->$passwordを渡され、それが$passwordする必要がありますのみ

関連する問題