You are here

function password_policy_constraint_username_validate in Password Policy 6

Same name and namespace in other branches
  1. 7 constraints/constraint_username.inc \password_policy_constraint_username_validate()

Password validation.

1 call to password_policy_constraint_username_validate()
PasswordPolicyTestCase::testUsernameConstraint in tests/password_policy.test

File

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

Code

function password_policy_constraint_username_validate($password, $constraint, $uid) {
  $account = user_load(array(
    'uid' => $uid,
  ));
  if ($account->name == '') {
    return TRUE;
  }
  $username_lowercase = drupal_strtolower($account->name);
  $password_lowercase = drupal_strtolower($password);
  if ($constraint && strpos($password_lowercase, $username_lowercase) !== FALSE) {
    return FALSE;
  }
  return TRUE;
}