# $this-\>Auth-\>identify(); always returning false

**URL:** <https://discourse.cakephp.org/t/this-auth-identify-always-returning-false/4674>\
**Category:** Need Help\
**Created:** [August 7, 2018, 10:44am UTC](https://discourse.cakephp.org/t/this-auth-identify-always-returning-false/4674 "2018-08-07T10:44:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anujg1](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@anujg1](https://discourse.cakephp.org/u/anujg1)\
**Post date:** [August 7, 2018, 10:44am UTC](https://discourse.cakephp.org/t/this-auth-identify-always-returning-false/4674/1 "2018-08-07T10:44:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![rrd](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/rrd/32/113_2.png) [@rrd](https://discourse.cakephp.org/u/rrd)\
**Post date:** [August 7, 2018, 3:28pm UTC](https://discourse.cakephp.org/t/this-auth-identify-always-returning-false/4674/2 "2018-08-07T15:28:19Z")

</div>

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.

```php
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](https://book.cakephp.org/3.0/en/controllers/components/authentication.html#identifying-users-and-logging-them-in)

---

<div class="post-metadata">

**Author:** ![anujg1](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@anujg1](https://discourse.cakephp.org/u/anujg1)\
**Post date:** [August 8, 2018, 3:10am UTC](https://discourse.cakephp.org/t/this-auth-identify-always-returning-false/4674/3 "2018-08-08T03:10:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anujg1](https://avatars.discourse-cdn.com/v4/letter/a/35a633/32.png) [@anujg1](https://discourse.cakephp.org/u/anujg1)\
**Post date:** [August 8, 2018, 8:49am UTC](https://discourse.cakephp.org/t/this-auth-identify-always-returning-false/4674/4 "2018-08-08T08:49:59Z")

</div>

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
