I have this code:
$user = User::where([
['email', '=', $request->email],
['password', '=', bcrypt($request->password)],
])->first();
if(count($user) > 0) {
return response()->json(['access_token' => $user->api_token, 'code' => '202'], 202);
}
else
{
return response()->json(['message' => 'Please provide a valid email or password', 'code' => '200'], 200);
}
But the problem is that it returns that the user does not exist because the password with bcrypt does not match. How can I make that the password that I am inserting and the database match?
Thanks
Question: User object based on username and Password without login.
Approach:
Step 1: Retrieve User based on email.
$user = User::where('email','=', $request->email);
Step 2: Check password is matching or not?
$isValidUser = false;
//If there is no user associated with email address.
if($user != null){
$isValidUser = Hash::check($request->password, $user->getAuthPassword()); //returns true/false
}
if($isValidUser) {
return response()->json(['access_token' => $user->api_token, 'code' => '202'], 202);
}
else
{
return response()->json(['message' => 'Please provide a valid email or password', 'code' => '200'], 200);
}