public function AuthDecorator::authenticate in Mail Login 8.2
Validates user authentication credentials.
Parameters
string $username: The user name to authenticate.
string $password: A plain-text password, such as trimmed text from form values.
Return value
int|bool The user's uid on success, or FALSE on failure to authenticate.
Overrides UserAuthInterface::authenticate
File
- src/
AuthDecorator.php, line 45
Class
- AuthDecorator
- Validates user authentication credentials.
Namespace
Drupal\mail_loginCode
public function authenticate($username, $password) {
$config_factory = \Drupal::configFactory();
$config = $config_factory
->get('mail_login.settings');
// If we have an email lookup the username by email.
if ($config
->get('mail_login_enabled') && !empty($username)) {
if (filter_var($username, FILTER_VALIDATE_EMAIL)) {
$account_search = $this->entityTypeManager
->getStorage('user')
->loadByProperties([
'mail' => $username,
]);
if ($account = reset($account_search)) {
$username = $account
->getAccountName();
}
}
else {
if ($config
->get('mail_login_email_only')) {
// Display a custom login error message.
\Drupal::messenger()
->addError(t('Login by username has been disabled, please use email address instead.'));
return NULL;
}
}
}
return $this->userAuth
->authenticate($username, $password);
}