Error during Auth::attempt($credentials)
. Followed https://laravel.com/docs/11.x/authentication#authenticating-users
I've created simple seeder:
$hashedPassword = Hash::make('password');
User::factory()->create([
'name' => 'Admin User',
'login' => 'admin',
'password' => $hashedPassword,
'role' => 'Admin',
]);
Phpmyadmin
I am trying to log in user with
public function loginUser(Request $request)
{
$credentials = $request->only('login', 'password');
if (Auth::attempt($credentials)) {
$request->session()->regenerate();
return redirect()->intended('/');
}
return back()->withErrors(['login' => 'Invalid login or password']); // Redirect back with error message
}
I am getting error even if password in DB is hashed. Did I miss something ?
In my case the problem solved when i change my hashed password in database from starting '$2a$' to '$2y$'
eg: $2a$12$POGG9oYZvS/8ijd8PiA3Q.bxTMMv4Ca77nIdZ6VFOEJOQGtM4ltUC
to this, $2y$12$POGG9oYZvS/8ijd8PiA3Q.bxTMMv4Ca77nIdZ6VFOEJOQGtM4ltUC
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