Skip to content

Issue #3182013 by mably: Integration with Password policy module

Closes #3182013

Then you simply need to implement the event on the Password Policy side:

  public function resetPasswordValidation(ResetPasswordValidationEvent $event): void {
    $form_state = &$event->getFormState();
    $user = $event->getUser();
    $passwords = \Drupal::request()->request->all('pass');
    /** @var $validation_report \Drupal\password_policy\PasswordPolicyValidationReport */
    $validation_report = \Drupal::service('password_policy.validator')
      ->validatePassword(
        reset($passwords),
        $user,
        $user->getRoles()
      );
    if ($validation_report->hasErrors()) {
      $form_state->setErrorByName('pass2', $validation_report->getErrors());
    }
  }

  function resetPasswordUpdate(ResetPasswordUpdateEvent $event) {
    $user = &$event->getUser();
    $date = \Drupal::service('date.formatter')->format(\Drupal::time()->getRequestTime(), 'custom', DateTimeItemInterface::DATETIME_STORAGE_FORMAT, DateTimeItemInterface::STORAGE_TIMEZONE);
    $user->set('field_last_password_reset', $date);
    $user->set('field_password_expiration', '0');
    $user->set('field_pending_expire_sent', '0');
  }
Edited by Frank Mably

Merge request reports

Loading