As my title mentioned, I am trying to login using auth()->attempt($credentials, false)
but it always return false
.
After further digging into the problem, I finally found that it was due to this:
public function validateCredentials(UserContract $user, array $credentials)
{
$plain = $credentials['password'];
return $this->hasher->check($plain, $user->getAuthPassword());
}
The $user->getAuthPassword()
returns null
even though the $user
have password on the original while I dump it out.
Actually this is very basic mistake. As I had mixed with some other programming language style of code (getter and setter).
I set a password
variable on the User::class.
By such, when it retrieving $user->getAuthPassword()
it will take the variable data instead of attribute data.
I'm sharing this knowledge in case someone else encounters the same issue. As I tried to solve this problem for about 2 days and wasn't able to find anything.