function username_enumeration_prevention_pass_validate in Username Enumeration Prevention 8
Same name and namespace in other branches
- 6 username_enumeration_prevention.module \username_enumeration_prevention_pass_validate()
- 7 username_enumeration_prevention.module \username_enumeration_prevention_pass_validate()
Overrides user_pass_validate() found in user.pages.inc.
1 string reference to 'username_enumeration_prevention_pass_validate'
File
- ./
username_enumeration_prevention.module, line 44 - Main file for the Username Enumeration Prevention module.
Code
function username_enumeration_prevention_pass_validate($form, FormStateInterface $form_state) {
$name = trim($form_state
->getValue('name'));
// Try to load by email.
$account = user_load_by_mail($name);
if (empty($account)) {
// No success, try to load by name.
$account = user_load_by_name($name);
}
if ($account && $account
->id() && $account
->isActive()) {
$form_state
->setValueForElement([
'#parents' => [
'account',
],
], $account);
}
else {
\Drupal::logger('username_enumeration_prevention')
->notice('Blocked user attempting to reset password.');
}
$form_state
->set('username_enumeration_prevention_blocked', !empty($form_state
->getErrors()));
// Clear errors so they are not displayed to the end-user.
$form_state
->clearErrors();
}