How to modify login api so users can also login with registration?
I want that users can login with the registration number assigned to them or email. I have working api which only login users with email
public $successStatus = 200;
public function login(){
if(Auth::attempt(['email' => request('email'), 'password' => request('password')])){
$user = Auth::user();
$success['token'] = $user->createToken('MyApp')-> accessToken;
return response()->json(['success' => $success], $this-> successStatus);
}
else{
return response()->json(['error'=>'Unauthorised'], 401);
}
}
Auth::attempt([
'email' => request('email'),
'password' => request('password')
])
You probably hash passwords before you store them in your data base, if so, then
Auth::attempt([
'email' => request('email'),
'password' => bcrypt(request('password')) // hash the password, then try to login
])
Please or to participate in this conversation.