You are here

class And_Constraint in Password Policy 5

Hierarchy

Expanded class hierarchy of And_Constraint

1 string reference to 'And_Constraint'
PasswordPolicyTest::testConstraints in tests/password_policy.test

File

constraints/constraint_and.php, line 5

View source
class And_Constraint extends Constraint {
  var $constraints;
  var $expiration;
  var $warning;
  function And_Constraint() {
    $this->constraints = array();
  }
  function validate($plaintext_password, $user = NULL) {
    foreach ($this->constraints as $constraint) {
      if (!$constraint
        ->validate($plaintext_password, $user)) {
        return 0;
      }
    }
    return 1;
  }
  function getDescription() {
    return $this
      ->getValidationErrorMessage();
  }
  function getValidationErrorMessage($plaintext_password = NULL, $user = NULL) {
    $reason = '<ul>';
    foreach ($this->constraints as $constraint) {
      $msg = NULL;

      // if we have a password to test, then indicate in the validation error
      // message, which constraints passed and which failed.
      if (isset($plaintext_password)) {
        if ($constraint
          ->validate($plaintext_password, $user)) {
          $msg = t('(PASS)') . ' ' . $constraint
            ->getValidationErrorMessage();
        }
        else {
          $msg = t('(FAIL)') . ' ' . $constraint
            ->getValidationErrorMessage();
        }
      }
      else {
        $msg = $constraint
          ->getValidationErrorMessage();
      }
      $reason .= "<li>{$msg}</li>";
    }
    return $reason . '</ul>';
  }
  function addConstraint($constraint) {
    array_push($this->constraints, $constraint);
  }
  function getConstraints() {
    return $this->constraints;
  }
  function getExpiration() {
    return $this->expiration;
  }
  function setExpiration($expiration) {
    $this->expiration = $expiration;
  }
  function getWarning() {
    return $this->warning;
  }
  function setWarning($warning) {
    $this->warning = $warning;
  }

}

Members