constraint_and.php in Password Policy 5
File
constraints/constraint_and.php
View source
<?php
include_once 'constraint.php';
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 (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;
}
}