When I register a user, using Laravels built in controller Auth\RegisterController.php, everything works great and I'm immediately logged in. The problem is when I logout and try to login via Auth\LoginController.php, It shows that the password is incorrect. Code looks like this:
RegisterController.php
$user = $this->create([
'name' => $request['name'],
'email' => $request['email'],
'password' => Hash::make($request['password']),
]);
LoginController.php
if(!Auth::attempt(request(['email', 'password']))) {
return back()->withErrors([
'message' => 'Wrong Emial or Password!'
]);
}
I've checked the database and everything seems ok.
What is also weird about this problem, is when I hash the password ( using Hash::make('password') ) with php artisan tinker and then replace it in the database for the same user, everything works...
You shouldn't send a hashed password to the create() function, the function takes care of that. The reason you can't login is because you hashed the password twice.
$user = $this->create([
'name' => $request['name'],
'email' => $request['email'],
'password' => $request['password'],
]);
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