I'm currently trying to change my cakephp login from using the username field to using the email field.
When using the username field, the login works fine, here's the code for the login with username:
login.ctp
<?php
echo $this->Form->create('User');
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->end(__('Login'));
?>
UsersController.php
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add', 'login'); // Letting users register themselves
$this->Auth->fields = array('username' => 'username', 'password' => 'password');
}
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
$this->Session->setFlash(__('worked'));
} else {
debug($this->data);
$this->Session->setFlash(__('Invalid username or password, try again'));
}
}
}
AppController
public $components = array('Session', 'Auth');
So this all works fine, I can login with test details.
So to change this to using an email, all I have done is:
Change the input in login.ctp from username to email
echo $this->Form->input('email');
Change the fields array in userscontroller from username to email
$this->Auth->fields = array('username' => 'email', 'password' => 'password');
Change the database field from username to email
I then try to login using the same test details and it tells me they are incorrect.
Does anyone have any idea why this wouldn't work?