I'm using the last version of CakePHP (2.5.4 if I'm right) & I have a problem when trying to login.
I have a table called "Accounts", & my controller is called "UsersController.php", model => "User.php" etc. There seems to be no problem with that, because I'm setting the default table to "Accounts". I have already made a view to signup, and I'm using md5 to hash passwords and it's working perfectly.
But, when I want to login, it ALWAYS returns false & it doesn't log me in.
Here is my login function in UsersController.php:
function login(){
if($this->request->is('post'))
{
if($this->Auth->login())
{
$this->Session->setFlash("Vous êtes maintenant connecté !", "notif");
$this->redirect('/');
} else {
$this->Session->setFlash("Les identifiants sont incorrects", "notif", array('type' => 'danger'));
debug(Security::hash($this->request->data['User']['PasswordHash']));
}
}
}
Here is the form from login.ctp :
<?= $this->Form->input('Login', array('placeholder' => 'Login', 'label' => false)); ?>
<b class="tooltip tooltip-bottom-right">Votre nom de compte</b>
</label>
</section>
<section>
<label class="input">
<i class="icon-append fa fa-lock"></i>
<?= $this->Form->input('PasswordHash', array('placeholder' => 'Mot de passe', 'label' => false)); ?>
<b class="tooltip tooltip-bottom-right">Votre mot de passe!</b>
</label>
</section>
</fieldset>
<fieldset>
<section>
<h4>Mot de passe perdu ?</h4>
<p><a style='color:#009900' href="#">Cliquez ici</a> pour réinitialiser le mot de passe.</p>
</section>
</fieldset>
<footer>
<center>
<?php $options = array(
'class' => 'btn-u',
'label' => 'Connexion'
) ?>
<?= $this->form->end($options); ?>
I FORGOT TO MENTION THAT MY COLUMNS AREN'T username & password, but rather Login & PasswordHash
Also, here is my AppController.php:
class AppController extends Controller {
public $components = array(
'Session',
'Cookie',
'Auth');
function beforeFilter(){
Security::setHash('md5');
$this->Auth->allow();
$this->Auth->authenticate = array(
'Form' => array(
'fields' => array('username' => 'Login', 'password' => 'PasswordHash'),
)
);
}
}
I can't login and I don't understand why. My request query looks like this :
SELECT `User`.`Id`, `User`.`Login`, `User`.`PasswordHash`, `User`.`Nickname`, `User`.`Role`, `User`.`AvailableBreeds`, `User`.`Ticket`, `User`.`SecretQuestion`, `User`.`SecretAnswer`, `User`.`Lang`, `User`.`Email`, `User`.`CreationDate`, `User`.`Tokens`, `User`.`NewTokens`, `User`.`LastVote`, `User`.`RecordVersion` FROM `madara`.`accounts` AS `User` WHERE `User`.`Login` = 'Twoast' LIMIT 1
The debug shows me the same hashes as in my table Accounts. I am not sure what I am doing wrong.
Thanks in advance!
loginreturns false if you are already logged in.) My login method first checks$this->Auth->loggedIn()is false before anything else is process. - AgRizzo