I'm playing around with CakePHP and can't seem to get the login working. It seems that $this->Auth->identify() is constantly returning false and not allowing me to login.
I've read all previous posts regarding my issue, however, none have provided me with a solution. The users I am trying to log in as have all been created using the cake password hasher, which I have checked have been stored in the database. I have checked the password field length in the database, which is set to varchar (255), I've checked the Auth => authenticate => Form => fields are set to the correct values (the login.ctp fields are also correct). I also tried changing the $this->Form->control() to $this->Form->input() as someone suggested, with no luck.
AppController:
$this->loadComponent('Auth', [
'loginRedirect' => [
'controller' => 'Users',
'action' => 'classes'
],
'logoutRedirect' => [
'controller' => 'Users',
'action' => 'index'
]
]);
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => [
'username' => 'email',
'password' => 'password'
]
]
],
'loginAction' => [
'controller' => 'Users',
'action' => 'login'
]
]);
login() function in UsersController:
public function login()
{
if ($this->request->is('post')) {
$user = $this->Auth->identify();
pj($user);
if ($user) {
$this->Auth->setUser($user);
return $this->redirect(['controller' => 'users']);
}
$this->Flash->error(__('Invalid username or password, try again'));
}
}
login.ctp:
<div class="users form">
<?= $this->Form->create() ?>
<fieldset>
<legend><?= __('Please enter your username and password') ?></legend>
<?= $this->Form->input('email') ?>
<?= $this->Form->input('password') ?>
</fieldset>
<?= $this->Form->button(__('Login')); ?>
<?= $this->Form->end() ?>
</div>
EDIT: I forgot to add that I can successfully add users, I just can't log them in.
PASSWORD
column in the database? – Oerd