Answer the question
In order to leave comments, you need to log in
Why does Auth::attempt return false when given a username and password that exist in the database?
Good day!
I'm trying to write my own module for working with users, but I'm stuck on authorization. Everything is elementary in the documentation:
if (Auth::attempt(['login' => $request->login, 'password' => $request->password]))
return 'Пользователь авторизован';
else
return 'Пользователь не авторизован';
Auth::attempt(['login' => 'login', 'password' => 'f394h0wxfc9t54hgdc78w9f...']) <= pbkdf2-хеш пароля длинной 75 символов
public function getAuthPassword() {
return $this->pass;
}
gave nothing to the user model. How to specify your set of fields in Auth::attempt? public function login(Request $request) {
$user = User::whereLogin($request->login)->first();
$user_db_pass = hash_pbkdf2("sha256", $request->pass, $user->salt, 1000, 75);
//dd(Auth::attempt(['login' => 'admin', 'password' => 'c0b6de9afb4a16e83cba60e5946a87d84a6333f7064237126c0e58aa03699d86e43965e643a']));
if ($user->password == $user_db_pass) {
if (Auth::attempt(['login' => $request->login, 'password' => $user_db_pass]))
return redirect()->intended(route('users.profile'));
else
return $user->password.'<br>'.$user_db_pass;
}
}
Answer the question
In order to leave comments, you need to log in
And why are you passing the password hash there instead of the password itself? If you have your own password hashing mechanism, write a wrapper for it , or don't use Auth::attempt
it, because it hashes passwords inside (that's amazing!) when comparing.
PS And yes, in this context, not "authorization", but "authentication".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question