Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5 Auth: These credentials do not match our records

I'm just starting out with Laravel 5, I come from Laravel 4 environment so it shouldn't be too hard.

I heard L5 comes with a built-in authentication system which is neat. I've set everything up from database to views.

The registration process is working correctly and after that it logs me in automatically. but when I log out and try to log back in, I get this error:

These credentials do not match our records.

I'm not sure what's wrong. do I have to write the login controller manually or how does it work in L5?

like image 245
Halnex Avatar asked Apr 04 '15 23:04

Halnex


3 Answers

In addition to @mervasdayi solution, a good way to hash passwords in setPasswordAttribute avoiding rehashing problems could be this:

public function setPasswordAttribute($password){
    $this->attributes['password'] = Hash::needsRehash($password) ? Hash::make($password) : $password;
}
like image 87
Gerard Reches Avatar answered Oct 08 '22 12:10

Gerard Reches


I had the same issue. The reason for mine was that I defined setPasswordAttribute in my User model so every time, I enter plain password, it hashes before sending to DB.

public function setPasswordAttribute($password)
{
    $this->attributes['password'] = \Hash::make($password);
}

and in my db:seed, I was creating a user with hashed password with Hash::make("password"), too. So laravel hashes hashed password :)

In laravel version 5.* you don't need to hash input password for Auth, because Auth manages it itself. you just have to pass {{csrf_field()}} through form.

like image 41
mervasdayi Avatar answered Oct 08 '22 12:10

mervasdayi


Further to what @mervasdayi & Gerard Reches have suggested. Just thought I'd make a note that you will need to include

use Illuminate\Support\Facades\Hash;

at the top of your User model when adding in these fixes.

like image 34
Grant Avatar answered Oct 08 '22 11:10

Grant