You are here

public function LogintobogganPasswordLengthValidator::validate in LoginToboggan 8

Check lenth of password.

File

src/Plugin/Validation/Constraint/LogintobogganPasswordLengthValidator.php, line 18

Class

LogintobogganPasswordLengthValidator
Validates length of password.

Namespace

Drupal\logintoboggan\Plugin\Validation\Constraint

Code

public function validate($value, Constraint $constraint) {
  $gotpass = $value
    ->getValue();
  if (!empty($gotpass)) {
    $pass = $value
      ->get(0)->value;
    $min_pass_length = \Drupal::config('logintoboggan.settings')
      ->get('minimum_password_length');
    if (strlen($pass) > 0 && strlen($pass) < $min_pass_length) {
      $this->context
        ->addViolation($constraint->message, [
        '%length' => $min_pass_length,
      ]);
    }
  }
}