Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 5: Login password doesn't match with saved one

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...

like image 349
Sushiarkt Avatar asked Dec 18 '25 08:12

Sushiarkt


1 Answers

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'],
]);
like image 114
Jerodev Avatar answered Dec 19 '25 20:12

Jerodev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!