I have done all the settings for login in cakephp 3.2,but while login it is returning false.
login function in usercontroller
public function login() {
$this->viewBuilder()->layout('');
if ($this->request->is('post')) {
$user = $this->Auth->identify();
pj($user);//returning false
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error(__('Invalid username or password, try again'));
}
}
This function $user = $this->Auth->identify(); is always returning false.
Why can't i login?
In data base password is stored as
$2y$10$4aD6Ye6YcmPGKgI/CmhJBO0E//9tV.KvhJIOFAhajyqt8vfxDVASC
I am getting the email and password from $this->request->data.
Any suggestion will highly appreciate. thank you in advance.
Please change like below:-
First in your controller add this code (best will be App controller):-
public function initialize()
{
parent::initialize();
$this->loadComponent('Auth', [
'loginAction' => [
'controller' => 'Users',
'action' => 'login',
'plugin' => 'Users'
],
'authError' => 'Did you really think you are allowed to see that?',
'authenticate' => [
'Form' => [
'fields' => ['username' => 'email']
]
],
'storage' => 'Session'
]);
}
And then use your code. It will be work properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With