2016-10-13 22 views
0

おはようございます、Issue with DefaultPasswordHasher CakePHP

私は自分のWebアプリケーションへのログインに問題があります。ユーザーが登録されている場合

//Register 
public function register() { 
    $user = $this->Users->newEntity(); 
    if($this->request->is('post')) { 
     $this->request->data('status', '0'); 
     $this->request->data('role', '0'); 
     $user = $this->Users->patchEntity($user, $this->request->data); 
     if($this->Users->save($user)) { 

      $this->Flash->success('You are registered and can login'); 
      return $this->redirect(['action' => 'login']); 
     } else { 
      $this->Flash->error('You are not registered'); 
     } 
    } 
    $this->set(compact('user')); 
    $this->set('_serialize', ['user']); 
} 

私は、ログインカント(そして、私はなぜ知らない)が、私は、ログインするかどうか:私は(私の意見では)エラーがない私のアプリに登録してい

古いユーザーのパスワードを変更しています - >古いユーザーがログインできる

問題の原因がわかりません。

ログイン:

//Login 
public function login() { 
    if($this->request->is('post')) { 
     $user = $this->Auth->identify(); 

     //dump($user); 
     //die(); 
     if($user) { 
      if($user['status'] == '1') { 
       $this->Auth->setUser($user); 
       return $this->redirect(['controller' => 'tasks']); 
      }elseif($user['status'] == '0') { 
       $this->Flash->error('You are not authorized to Log In. Please contact with Admin of Application'); 
      } 
     } else { 
      //Bad Login 
      $this->Flash->error('Incorrect Login or Password'); 
     } 
    } 
} 

興味深いのは、その私がログインしていると私は私が... "偽" を受信して​​い

dump($user); 
die(); 

を書いたとき

Login.ctp :

<div class="index large-4 medium-4 large-offset-4 medium-offset-4 columns"> 
<div class="panel"> 
    <center><?= $this->HTML->image('small_logo.png'); ?></center> 
    <?= $this->Form->create(); ?> 
     <?= $this->Form->input('email'); ?> 
     <?= $this->Form->input('password'); ?> 
     <center><?= $this->Form->submit('Log In', array('class' => 'button')); ?></center> 
    <?= $this->Form->end(); ?> 
</div> 

私はこの問題が 'DefaultHasherPassword'と関連していると思いますが、どこに問題があるのか​​、どのように解決するべきかはわかりません。助けてください。

新しいユーザーカントログインのようなその、しかし、ユーザーが変更された(パスワードが変更) - 。彼は、ログインすることができます

+0

もしあなたのappControllerの認証コードを共有すれば、より簡単にあなたを助けるでしょう – tarikul05

答えて

0

あなたが共有していなかったので、あなたは、電子メール(いないことを確認として、フィールド名を追加するのを忘れすることができますあなたのコード)

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