You are here

function password_policy_constraint_complexity_validate in Password Policy 6

Password validation.

1 call to password_policy_constraint_complexity_validate()
PasswordPolicyTestCase::testComplexityConstraint in tests/password_policy.test

File

constraints/constraint_complexity.inc, line 28
Password policy constraint callbacks.

Code

function password_policy_constraint_complexity_validate($password, $constraint, $uid) {
  $length = drupal_strlen($password);
  $num = 0;
  $upper = 0;
  $lower = 0;
  $digit = 0;
  $punct = 0;
  for ($i = 0; $i < $length; $i++) {
    if (ctype_upper($password[$i])) {
      $upper = 1;
    }
    elseif (ctype_lower($password[$i])) {
      $lower = 1;
    }
    elseif (ctype_digit($password[$i])) {
      $digit = 1;
    }
    elseif (ctype_punct($password[$i])) {
      $punct = 1;
    }
  }
  $num = $upper + $lower + $digit + $punct;
  return $num >= $constraint;
}