I want to use user_password instead of just password for the name of the password column for the database of my API. So here is the code of the login() method to retrieve the token in my PassportController:
public function login() {
if (Auth::attempt(['user_login' => request('login'), 'password' => request('user_password')])) {
$user = Auth::user();
$success['token'] = $user->createToken('ToutelaBreizh')->accessToken;
return response()->json(['success' => $success], $this->successStatus);
} else {
return response()->json(['error' => 'Unauthorised.'], 401);
}
}
The parameters of the request to this controller are login and password.
The problem is when I go to the route associated to this controller, let's say POST /api/login. I get this error:
ErrorException: Undefined index: password in file ... EloquentUserProvider.php on line 133
[First lines of the stack trace...]
- ... PassportController.php:21
The 21st line in my PassportController is the second line of the login function I posted above and indeed, the password field is not informed in the credentials I wrote: I wrote user_password instead of password, but the string password is hard coded in the EloquentUserProvider.php, line 133:
public function validateCredentials(UserContract $user, array $credentials)
{
$plain = $credentials['password'];
return $this->hasher->check($plain, $user->getAuthPassword());
}
As suggested by this answer, I tried to override the validateForPassportPasswordGrant($password) in the User.php model but it didn't help:
public function validateForPassportPasswordGrant($password)
{
return Hash::check($password, $this->user_password);
}
How should I do to have user_password in my database and not password?
Thank you for your help.