Hello, I'm looking for a way to authenticate a user by email and password and retrieve the user object but I don't want to log the user in. Is there a way this can be done with Laravel's inbuilt authentication functions.
I'm looking for a way to authenticate a user by email and password ... but I don't want to log the user in
What is authentication if not to sign in???
Anyway... you need to check the hashed password against the given password:
// Find the user by email
$user = User::where('email', $email)->first();
// Check the given password against the hashed password
if (! Hash::check($password, $user->password)) {
return null;
}
return $user;
Hi @tykus, thanks for your reply. So, my use case is to first check username/password, then send out an token (OTP) to the users email / phone sms and once they enter the token, only then log the user in (i.e. add the user id to the session). Thought there would be some function on the Auth facade I could use rather than query the DB with direct queries, may be there isn't :(