anujg1
August 7, 2018, 10:44am
1
Right now I am working on authentication process, changing it from 2.7.5 to 3.6.
I have change from auth login to this->Auth->identify() but it is giving boolean (false).
getting below output on debugging:
\src\Controller\UsersController.php (line 36 )
[ ‘User’ => [ ‘username’ => ‘leon’, ‘password’ => ‘anuj’ ], ‘btnSubmit’ => ‘’ ]
\src\Controller\UsersController.php (line 37 )
false
User Controller :
function login() {
$this->set(‘title_for_layout’,‘Please Login’);
$this->layout = ‘login’;
if ($this->request->is(‘post’)) {
$user = $this->Auth->identify();debug($user);die;
if ($user) {
$this->Flash->set(‘You are logged in!’, ‘flash_good’);
return $this->redirect($this->Auth->redirectUrl());
}
else {
$this->Flash->set(
__(‘Username or password is incorrect’),
[‘element’ => ‘default’]
);
}
}
}
Any suggestions?
Regards
Anuj
rrd
August 7, 2018, 3:28pm
2
Your code seems to be OK (however I would suggest a few changes).
But you are missing to set the user for the auth component.
if ($user) {
$this->Auth->setUser($user);
$this->Flash->set(‘You are logged in!’, ‘flash_good’);
https://book.cakephp.org/3.0/en/controllers/components/authentication.html#identifying-users-and-logging-them-in
anujg1
August 8, 2018, 3:10am
3
Yes, I agree with you but $this->Auth->identify(); is giving false.
I have already tried with the above code but its going in else condition because its unable to find anything as $this->Auth->identify(); returning false.
Thanks
Regards
Anuj
anujg1
August 8, 2018, 8:49am
4
Hi,
This issue has been resolved.
Password was not matching after converting into hash so I have created a custom password matching while following the cakephp 2.7.5 and now its working fine. I am able to login now.
Thanks!
Regards
Anuj