Jonathan Cunza Jonathan Cunza - 1 year ago 56
PHP Question

Not validate user cakephp 3

I will see that such a login where I followed all the steps according to the documentation with the only difference that my login is another pun other than the default layout that is within my project structure I have something

\app\src\Tempalte\layout\default.ctp public.ctp

well up there my layouts now the auth component

class AppController extends Controller {
'authorize' => ['Controller'],
'authenticate' => [
'Form' => [
'userModel' => 'Usuarios',
'fields' => [
'username' => 'usuario',
'password' => 'password'
'loginAction' => [
'controller' => 'Usuarios',
'action' => 'login'
'authError' => 'Ingrese Datos',
'loginRedirect' => [
'controller' => 'Portal',
'action' => 'dashboard'

my controller user

public function login() {
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
return $this->redirect($this->Auth->redirectUrl());
} else {
$this->Flash->error('Usuario y/o clave inválido',['key' => 'auth']);

my layout public that would come to be my login

<?= $this->Flash->render('auth') ?>
<?= $this->Form->create() ?>
<div class="form-group">
<div class="input-group">
<i class="input-group-addon icon-user"></i>
<?= $this->Form->text('usuario',['placeholder' => 'Usuario','class'=>'form-control']) ?>
<div class="form-group">
<div class="input-group">
<i class="input-group-addon icon-key"></i>
<?= $this->Form->password('password',['placeholder' => 'Contraseña','class'=>'form-control']) ?>
<div class="form-group">
<?= $this->Html->link('Olvidaste tu Contraseña','/usuarios/password');?>
<?= $this->Form->button('Ingresar',['class'=>'btn btn-inverse btn-right'])?>
<?= $this->Form->end()?>

load everything but always sends the message Usuario y/o clave inválido

this is my table

`id_usuario` int(11) NOT NULL,
`usuario` varchar(50) DEFAULT NULL,
`password` varchar(50) DEFAULT NULL,

I was not supposed to miss more with that should work or whatever is doing wrong please help

Answer Source

Please check the following:

  1. You password field in the database table seems to be too short: varchar(50). It needs to be at least 60 characters long or better 255 to ensure the more comprehensive hashers would always work.
  2. Check that the user record has been created with the proper hasher.
  3. Ensure you put a call to $this->loadComponent('Auth') inside the initialize() method of your AppController. E.g.:

    class AppController extends Controller {
        public function initialize()
            $this->loadComponent('Auth', [...]);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download