<p>This doesn't work:</p>
<pre><code>$user = User::find()-&gt;email(&quot;bob@example.com&quot;)-&gt;one();
if ($user-&gt;authenticate(&quot;myClearTextPassword&quot;)) {
  // This is never true, so you never get here
}
</code></pre>
<p>Is this method broken, or am I using it incorrectly?</p>

CC BY-SA 4.0
2020-12-21T01:28:26.637Z
What does `$user->authError` return after you call the authenticate method?
Brad Bell
CC BY-SA 4.0
2020-12-21T05:57:33.627Z
Thanks for taking a look @BradBell. I get `invalid_credentials`, even when the password is correct.
David Jones
CC BY-SA 4.0
2020-12-23T20:32:40.307Z
Is the user in a soft-deleted state? Or do you have https://craftcms.com/docs/3.x/config/config-settings.html#preventuserenumeration set to `true`?
Brad Bell
CC BY-SA 4.0
2022-04-22T04:41:56.043Z
@BradBell I can confirm that this is not working still in 3.7.38.  preventUserEnumeration has not been set and should be defaulted to false.
biko
<authentication>
Does the authenticate method in the User class work?
# Does the authenticate method in the User class work?

(Asked by: username_0 on 2020-12-18)

This doesn't work:
$user = User::find()->email("bob@example.com")->one();
if ($user->authenticate("myClearTextPassword")) {
  // This is never true, so you never get here
}

Is this method broken, or am I using it incorrectly?

**Tags:** authentication
> **Comments:**
> **username_1**: What does `$user->authError` return after you call the authenticate method?  
> **username_0**: Thanks for taking a look @BradBell. I get `invalid_credentials`, even when the password is correct.  
> **username_1**: Is the user in a soft-deleted state? Or do you have https://craftcms.com/docs/3.x/config/config-settings.html#preventuserenumeration set to `true`?  
> **username_2**: @BradBell I can confirm that this is not working still in 3.7.38.  preventUserEnumeration has not been set and should be defaulted to false.  

---

## 0 answers

