0
votes

i'm making a online test web application, these are the controllers

  • Faculties
  • Students
  • Tests
  • Notes
  • Questions
  • Answers
  • TestQuestions
  • StudentResults
  • StudentsTests

Note : students and faculties both have different logins

I'm trying to login in Faculties Controller, i have load Auth component in App controller,

When I'm trying to login, it shows an error "username or password is incorrect"

This is the App controller

$this->loadComponent('Auth', [
                'loginAction'=> [
                    'controller'=>'Faculties',
                    'action'=> 'login',
                ],
                'authenticate' => [
                    'Form' => [
                        'userModel' => 'Faculties',
                        'fields' => ['username' => 'email', 'password' => 'password'],
                    ]
                ],
                'loginRedirect' => [
                    'controller' => 'Faculties',
                    'action' => 'index'
                ]
            ]);

This is the login function in Faculties controller

public function login()
    {
        if ($this->request->is('post'))
        {
            debug($this->request->getData());
            debug($this->Auth->identify());
            $faculty = $this->Auth->identify();
            if ($faculty)
            {
                $this->Auth-setUser($faculty);
                return $this->redirect($this->Auth->redirectUrl());
            }
            $this->Flash->error('Your username or password is incorrect');
        }
    }

view of login

<h1>Login</h1>
<?= $this->Form->create() ?>
<?= $this->Form->control('email') ?>
<?= $this->Form->control('password') ?>
<?= $this->Form->submit('Login') ?>
<?= $this->Form->end() ?>

faculties schema

CREATE TABLE IF NOT EXISTS `mydb`.`faculties` (
  `id` INT NOT NULL AUTO_INCREMENT COMMENT '',
  `email` VARCHAR(45) NOT NULL COMMENT '',
  `password` VARCHAR(45) NOT NULL COMMENT '',
  `first_name` VARCHAR(45) NOT NULL COMMENT '',
  `last_name` VARCHAR(45) NULL COMMENT '',
  `profile_pic` VARBINARY(8000) NULL COMMENT '',
  `mobile_no` INT(10) NOT NULL COMMENT '',
  `college` VARCHAR(100) NULL COMMENT '',
  `department` VARCHAR(100) NULL COMMENT '',
  `subjects` TEXT NULL COMMENT '',
  `created` DATETIME NULL COMMENT '',
  `modified` DATETIME NULL COMMENT '',
  PRIMARY KEY (`id`)  COMMENT '')
ENGINE = InnoDB

please help whats wrong in the code

1
what is your faculties database schema ? - tarikul05
i have added the schema, please help - Javed Saifi
do you encrypt your password? if you encrypt it then password VARCHAR(45) length 45 is not enough increase it and try again by registering - tarikul05
Yes sir, I'm using password hashing. - Javed Saifi
Right sir, I'm using password hashing. - Javed Saifi

1 Answers

0
votes
  • Verify the name of each fields (email or mail/ password or passwd)
  • Verify that you add inside src/Model/Entity/Faculty.php "function _setPassword"
  • debug the $faculty value maybe you have a problem with your validation (src/Model/Table/FacultyTable.php)