this framework uses the default USER model that I have setup in the namespace.
App/User.php fileemail and password to authenticateFor purposes of my project,
SE_Users.phpse_users and se_passwordI have every thing setup correctly. And it finds the custom table. But then I get the error message below:
1. in EloquentUserProvider.php line 116
2. at HandleExceptions->handleError('8', 'Undefined index: password', '/home/vagrant/Code/apiServer/vendor/laravel/framework/src/Illuminate/Auth/EloquentUserProvider.php', '116', array('user' => object(SE_Users), 'credentials' => array('user_email' => '[email protected]', 'user_password' => 'testpass'))) in EloquentUserProvider.php line 116
even though my field is called se_password it is still looking for password.
I found the issue in the file EloquentUserProvider.php in the validateCredentials function.
public function validateCredentials(UserContract $user, array $credentials)
{
$plain = $credentials['password'];
return $this->hasher->check($plain, $user->getAuthPassword());
}
Is this a bug? it is looking for the key password and this is hard coded?
Are you proposing a custom property for denoting the password attribute on the user model being validated?
@feeekkk from your response i take it that we can't select a custom property right now. hmm...
In terms of proposing it, I say, why not? With password hardcoded, its basically forcing users to have the field called password ... I don't think this is a good thing.
Maybe this functionality could live within JWTSubject as getPasswordIdentifier or something so all models would have to implement it? I'm not a huge fan of requiring all models to have to implement this though considering password is probably used 99% of the time...
Then validateCredentials could be changed to something like
public function validateCredentials(UserContract $user, array $credentials)
{
$plain = $credentials[$user->getPasswordIdentifier()];
return $this->hasher->check($plain, $user->getAuthPassword());
}
I'm not sure how well this would work, just an idea.
Ok. I am not used to writing php libraries. I am used to writing Swift/ObjectiveC libs for iOS.
My PHP still needs some work, so i can't understand what the code you wrote above says.
But is it basically this?
password keyIf it's that then i think this will be a good idea rather than requiring all users to have a field in their database called password. I wish others could chime in on this suggestion though
EloquentUserProvider is part of Laravel core, not this library. The password requirement is enforced by its defaults. However there are a number of ways to address this issue:
validateCredentials method (like you suggested) and probably have everything else inherit from EloquentUserProvider.password. Then if your $user->getAuthPassword() method works right everything should be peachy.(1) is the "more correct"/"more Laravel" way to do things, but (2) is a lot simpler, as long as you can get over the uneasiness of manually re-keying something.
You should also note that these problems should all go away with the new JWTGuard approach, but I can't recommend it quite yet because there aren't many instructions for it. Eventually that will probably be the preferred answer though.
@tdhsmith man thank you so much for this info!
Not a problem! :ok_hand:
I'm just chipping here to say that I too, have been having this problem.
My "user" model lets users login just by typing in a 6 digit code. Therefore, Laravel is none too happy when I point it at the model for this...which doesn't include a password field.
Do I need to create a new UserProvider that somehow returns my model? I'm feeling a bit lost here.
Most helpful comment
EloquentUserProvideris part of Laravel core, not this library. The password requirement is enforced by its defaults. However there are a number of ways to address this issue:validateCredentialsmethod (like you suggested) and probably have everything else inherit fromEloquentUserProvider.password. Then if your$user->getAuthPassword()method works right everything should be peachy.(1) is the "more correct"/"more Laravel" way to do things, but (2) is a lot simpler, as long as you can get over the uneasiness of manually re-keying something.
You should also note that these problems should all go away with the new
JWTGuardapproach, but I can't recommend it quite yet because there aren't many instructions for it. Eventually that will probably be the preferred answer though.