You are here

constraint_length.inc in Password Policy 6

Same filename and directory in other branches
  1. 7 constraints/constraint_length.inc

Password policy constraint callbacks.

File

constraints/constraint_length.inc
View source
<?php

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

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

/* Constraint API                                                           */

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

/**
 * Description of the constraint.
 */
function password_policy_constraint_length_description() {
  return array(
    'name' => t('Length'),
    'description' => t('Password must be longer than the specified minimum length.'),
  );
}

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

/**
 * Password validation.
 */
function password_policy_constraint_length_validate($password, $constraint, $uid) {
  $length = drupal_strlen($password);
  return $length >= $constraint;
}

/**
 * Javascript portion.
 */
function password_policy_constraint_length_js($constraint, $uid) {
  $s = '';
  $s .= "  if (!value.length || value.length<{$constraint}) {\n";
  $s .= "    strength=\"low\";\n";
  $s .= "    msg.push(translate.constraint_length);\n";
  $s .= "  }\n";
  return $s;
}

Functions

Namesort descending Description
password_policy_constraint_length_description Description of the constraint.
password_policy_constraint_length_error Error message of the constraint.
password_policy_constraint_length_js Javascript portion.
password_policy_constraint_length_validate Password validation.