class Digit_Placement_Constraint in Password Policy 5
Hierarchy
- class \Constraint
- class \Character_Constraint
- class \Digit_Placement_Constraint
- class \Character_Constraint
Expanded class hierarchy of Digit_Placement_Constraint
File
- constraints/
constraint_digit_placement.php, line 13
View source
class Digit_Placement_Constraint extends Character_Constraint {
function validate($plaintext_password, $user = NULL) {
$number_of_digits = 0;
for ($i = 0; $i < 10; $i++) {
$number_of_digits += substr_count($plaintext_password, "{$i}");
// help string count by sending it a string instead of an int
}
if ($number_of_digits < (int) $this->minimumConstraintValue) {
return preg_match("/(^\\d+)|(\\d+\$)/", $plaintext_password) != 1;
}
return TRUE;
}
function getDescription() {
return t('Minimum number of digits in the password to allow a digit in the first or last position in the password (e.g. 2abcdefg and abcdefg4 are unacceptable passwords, while 2qpcxrm3 and 99qpcxrm are allowed passwords when 2 is set here).');
}
function getValidationErrorMessage() {
return t('Password must have a minimum of %numChars %digits to place any digits at the start or end of the password.', array(
'%numChars' => $this->minimumConstraintValue,
'%digits' => format_plural($this->minimumConstraintValue, t('digit'), t('digits')),
));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Character_Constraint:: |
function | 4 | ||
Constraint:: |
property | |||
Constraint:: |
property | |||
Constraint:: |
property | |||
Constraint:: |
function | |||
Constraint:: |
function | |||
Constraint:: |
function | |||
Constraint:: |
function | |||
Constraint:: |
function | |||
Digit_Placement_Constraint:: |
function |
Overrides Character_Constraint:: |
||
Digit_Placement_Constraint:: |
function |
Overrides Character_Constraint:: |
||
Digit_Placement_Constraint:: |
function |
Overrides Character_Constraint:: |