You are here

constraint_lowercase.inc in Password Policy 7

Same filename and directory in other branches
  1. 6 constraints/constraint_lowercase.inc

Password policy constraint callbacks.

File

constraints/constraint_lowercase.inc
View source
<?php

/**
 * @file
 * Password policy constraint callbacks.
 */

/****************************************************************************/

/* Constraint API                                                           */

/****************************************************************************/

/**
 * Description of the constraint.
 */
function password_policy_constraint_lowercase_description() {
  return array(
    'name' => t('Lowercase'),
    'description' => t('Password must contain the specified minimum number of lowercase letters.'),
  );
}

/**
 * Error message of the constraint.
 */
function password_policy_constraint_lowercase_error($constraint) {
  return format_plural($constraint, 'Password must contain at least one lowercase character.', 'Password must contain at least @count lowercase characters.');
}

/**
 * Password validation.
 */
function password_policy_constraint_lowercase_validate($password, $constraint, $account) {
  $matches = array();
  $count = preg_match_all('/[a-z]/', $password, $matches);
  return $count >= $constraint;
}

/**
 * Javascript portion.
 */
function password_policy_constraint_lowercase_js($constraint, $account) {
  return <<<JS

    var count = (value.match(/[a-z]/g) || []).length;
    if (count < {<span class="php-variable">$constraint</span>}) {
      strength = 'low';
      msg.push(translate.constraint_lowercase);
    }
JS;
}

Functions

Namesort descending Description
password_policy_constraint_lowercase_description Description of the constraint.
password_policy_constraint_lowercase_error Error message of the constraint.
password_policy_constraint_lowercase_js Javascript portion.
password_policy_constraint_lowercase_validate Password validation.