You are here

function password_policy_constraint_character_types_validate in Password Policy 7

Password validation.

1 call to password_policy_constraint_character_types_validate()
PasswordPolicyTestCase::testCharacterTypesConstraint in tests/password_policy.test
Test character types constraint.

File

constraints/constraint_character_types.inc, line 29
Password policy constraint callbacks.

Code

function password_policy_constraint_character_types_validate($password, $constraint, $account) {
  $upper = preg_match('/[A-Z]/', $password);
  $lower = preg_match('/[a-z]/', $password);
  $digit = preg_match('/[0-9]/', $password);
  $punctuation_characters = '`~!@#$%^&*()_+=-|}{"?:><,./;\'\\[]';
  $punctuation_pattern = '/[' . preg_quote($punctuation_characters, '/') . ']/';
  $punctuation = preg_match($punctuation_pattern, $password);
  $count = $upper + $lower + $digit + $punctuation;
  return $count >= $constraint;
}