skip to Main Content

I use:

 public function postRegister(Request $request){
        $request->validate([
            'Email' => 'required|unique:users,Email',
            'Password' => ['required'],
        ]);
    
        $user = new User;
        $user->Email = $request->Email;
        $user->Password = Hash::make($request->password);
        $user->save();

        auth()->login($user);

        return redirect()->route('user.home');

 }

for my register function in laravel 10. It worked correctly and stores a new user in the database and the password was hashed correctly.

Register page:

Database saved the new user and hashed password:

Then I tried to login by using:

    public function postLogin(Request $request)
    {
        $credentials = $request->validate([
            'email' => ['required', 'email'],
            'password' => ['required'],
        ]);


        if(Auth::attempt($credentials)){
            return redirect()->route('user.home');
        }
        else return back()->withErrors([
            'Email' => 'Wrong email or password',
        ])->onlyInput('Email');

    }

in laravel 10.

Login page:

It comes up with an error:

This password does not use the Bcrypt algorithm.

Error:

I don’t know where I went wrong, please help me.

2

Answers


  1. I had this problem too and solved it in a non-obvious way. In general, if you have users with unhashed password in the users table, delete them. I had users without hashed password and only after I deleted them everything worked. I don’t know why it works like that, but whatever. Full code:

    <?php
    
    namespace AppHttpControllersAuth;
    
    use AppModelsUser;
    use IlluminateHttpRequest;
    use IlluminateValidationRule;
    use AppHttpControllersController;
    use IlluminateSupportFacadesAuth;
    use IlluminateSupportFacadesHash;
    
    class AuthController extends Controller 
    { 
        public function auth(Request $request){ 
     
            $request->validate([ 
                'login' => 'required', 
                'password' => 'required'
            ]); 
     
            if(Auth::attempt($request->only('login', 'password'))){ 
                return redirect('/'); 
            } 
     
            return back()->withInput()->withErrors([ 
                'login' => 'wrong login' 
            ]); 
     
        } 
    }
    
    Login or Signup to reply.
  2. I used this site(https://bcrypt.online/) to create a password and my problem was solved.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search