I have UsersController i'm trying to login using email and password fields, i'm also using Password Hashing, also my password field is of text datatype. which is working fine, but i'm unable to login, showing me an error
username or password is incorrect
UsersController.php
public function login()
{
if ($this->request->is('post'))
{
$user = $this->Auth->identify();
if ($user)
{
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error('Your username or password is incorrect.');
}
}
AppController.php
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Auth',[
'authenticate'=>[
'Form'=>[
'fields'=>[
'username'=>'email',
'password'=>'password'
]
]
],
'loginRedirect'=>[
'controller'=>'Users',
'action'=>'index'
],
'loginAction'=>[
'controller'=>'Users',
'action'=>'login'
]
]);
$this->Auth->allow(['add']);
}
login.ctp
<h1>Login</h1>
<?= $this->Form->create() ?>
<?= $this->Form->control('email') ?>
<?= $this->Form->control('password') ?>
<?= $this->Form->button('Login') ?>
<?= $this->Form->end() ?>
UsersTable
id char(100)
name varchar(100)
email varchar(100)
password (text)