class UserAuth in farmOS 2.x
Extends the core user.auth service to load users by their email.
Hierarchy
- class \Drupal\user\UserAuth implements UserAuthInterface
- class \Drupal\farm_login\UserAuth
Expanded class hierarchy of UserAuth
1 string reference to 'UserAuth'
- farm_login.services.yml in modules/
core/ login/ farm_login.services.yml - modules/core/login/farm_login.services.yml
1 service uses UserAuth
- farm_login.user.auth in modules/
core/ login/ farm_login.services.yml - Drupal\farm_login\UserAuth
File
- modules/
core/ login/ src/ UserAuth.php, line 10
Namespace
Drupal\farm_loginView source
class UserAuth extends CoreUserAuth {
/**
* {@inheritdoc}
*/
public function authenticate($username, $password) {
$uid = parent::authenticate($username, $password);
// If the parent failed to authenticate, try loading the user by email.
if (empty($uid) && !empty($username) && strlen($password) > 0) {
$account_search = $this->entityTypeManager
->getStorage('user')
->loadByProperties([
'mail' => $username,
]);
if ($account = reset($account_search)) {
if ($this->passwordChecker
->check($password, $account
->getPassword())) {
// Successful authentication.
$uid = $account
->id();
// Update user to new password scheme if needed.
if ($this->passwordChecker
->needsRehash($account
->getPassword())) {
$account
->setPassword($password);
$account
->save();
}
}
}
}
return $uid;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UserAuth:: |
protected | property | The entity type manager. | |
UserAuth:: |
protected | property | The password hashing service. | |
UserAuth:: |
public | function |
Validates user authentication credentials. Overrides UserAuth:: |
|
UserAuth:: |
public | function | Constructs a UserAuth object. |