0

In my users table I have a memorable_info column that contains a bcrypt value. I also have this as a field on my login form. So my login form fields in total are...

  • email
  • password
  • memorable_info

Obviously, I only want users to be logged in if they enter all 3 fields successfully. However, I cannot get it to check the memorable_info field. In my LoginController.php file, I have included the Auth facade and added the following functions...

protected function credentials(Request $request)
{
    return $request->only('email', 'password', 'memorable_info');
}

public function authenticate(Request $request)
{
    if (Auth::attempt(['email' => $request->email, 'password' => bcrypt($request->password), 'memorable_info' => bcrypt($request->memorable_info)])) {
        return redirect()->intended('dashboard');
    }
}

...however, this does not work and I constantly get the "These credentials do match our records." error.

Hoping someone has the answer on this please?

sgspragg
  • 19
  • 6

1 Answers1

0

you can refer to this link: https://stackoverflow.com/a/41348816/7620124[Laravel Auth::attempt() returns false]1

you don't have to bcrypt the password to attempt the authenticate function. So, here is my solution:

public function authenticate(Request $request)
{
    if (Auth::attempt(['email' => $request->email, 'password' => $request->password, 'memorable_info' => bcrypt($request->memorable_info)])) {
        return redirect()->intended('dashboard');
    }
}

Hope this solve the problem.