Recently I try to change the encoding of the password on CakePHP by directly adding a new file. Unfortunately I do not seem to connect, namely that her works perfectly with the class Simple in sha256
AppController
class AppController extends Controller {
public $components = array('Auth' => array(
'authenticate' => array(
'Form' => array(
'fields' => array('username' => 'email','password' => 'password'),
'passwordHasher' => array(
'className' => 'Custom'),
'scope' => array('active' => '1')
)
)
));
UsersController(login)
App::uses('CustomPasswordHasher', 'Controller/Component/Auth');
class UsersController extends AppController{
public function login()
{
$erreur = false;
if($this->request->is('post')) {
if(!empty($this->data)) {
if(!$this->Auth->user('id')) {
if($this->Auth->login()) {
echo 'ok';
} else {
$erreur = "Identifiant incorrect.";
}
} else {
$erreur = "Vous êtes déjà connecter.";
}
} else {
$erreur = "Veuillez saisir vos identifiants";
}
$this->set(compact('erreur'));
}
}
}
CustomPasswordHasher
App::uses('AbstractPasswordHasher', 'Controller/Component/Auth');
class CustomPasswordHasher extends AbstractPasswordHasher {
public function hash($password)
{
$before = substr(Configure::read('Security.salt'),0,43);
$after = substr(Configure::read('Security.salt'),43,42);
$chaine = $before.$password.$after;
return hash("sha256",$chaine);
}
public function check($password, $email, $hashType = null) {
$this->User = ClassRegistry::init('User');
$u = $this->User->find('first', array(
'fields' => array('user.password'),
'conditions' => array('user.email' => $email)
));
if($u) {
return $this->hash($password) == $u['User']['password'];
}
return false;
}
}
An idea where my problem might come?
Thank you !