Now all modules are in core modules folder
This commit is contained in:
parent
5ba1cdfa0b
commit
05b6a91b0c
1907 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Password policy constraint callbacks.
|
||||
*/
|
||||
|
||||
/****************************************************************************/
|
||||
/* Constraint API */
|
||||
/****************************************************************************/
|
||||
|
||||
/**
|
||||
* Description of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_alphanumeric_description() {
|
||||
return array('name' => t('Alphanumeric'), 'description' => t('Password must contain the specified minimum number of alphanumeric (letters or numbers) characters.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Error message of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_alphanumeric_error($constraint) {
|
||||
return format_plural($constraint, 'Password must contain at least one alphanumeric (letter or number) character.', 'Password must contain at least @count alphanumeric (letter or number) characters.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Password validation.
|
||||
*/
|
||||
function password_policy_constraint_alphanumeric_validate($password, $constraint, $uid) {
|
||||
$length = drupal_strlen($password);
|
||||
$num = 0;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (ctype_alnum($password[$i]))
|
||||
$num++;
|
||||
}
|
||||
return $num >= $constraint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript portion.
|
||||
*/
|
||||
function password_policy_constraint_alphanumeric_js($constraint, $uid) {
|
||||
$s = '';
|
||||
$s .= " var i=0;\n";
|
||||
$s .= " var num=0;\n";
|
||||
$s .= " var chr=\"\";\n";
|
||||
$s .= " while(i<value.length) {\n";
|
||||
$s .= " chr=value.charAt(i);\n";
|
||||
$s .= " if(chr.toUpperCase() != chr.toLowerCase() || \"1234567890\".indexOf(chr) != -1) {\n";
|
||||
$s .= " num++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " i++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " if (num<$constraint) {\n";
|
||||
$s .= " strength=\"low\";\n";
|
||||
$s .= " msg.push(translate.constraint_alphanumeric);\n";
|
||||
$s .= " }\n";
|
||||
return $s;
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Password policy constraint callbacks.
|
||||
*/
|
||||
|
||||
/****************************************************************************/
|
||||
/* Constraint API */
|
||||
/****************************************************************************/
|
||||
|
||||
/**
|
||||
* Description of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_complexity_description() {
|
||||
return array('name' => t('Complexity'), 'description' => t('Password must contain the specified minimum number of character types (lowercase, uppercase, digit or punctuation).'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Error message of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_complexity_error($constraint) {
|
||||
return format_plural($constraint, 'Password must contain at least one character of the following types: lowercase, uppercase, digit or punctuation.', 'Password must contain at least @count characters of different types (lowercase, uppercase, digit or punctuation).');
|
||||
}
|
||||
|
||||
/**
|
||||
* Password validation.
|
||||
*/
|
||||
function password_policy_constraint_complexity_validate($password, $constraint, $uid) {
|
||||
$length = drupal_strlen($password);
|
||||
$num = 0;
|
||||
$upper = 0;
|
||||
$lower = 0;
|
||||
$digit = 0;
|
||||
$punct = 0;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (ctype_upper($password[$i])) {
|
||||
$upper = 1;
|
||||
}
|
||||
elseif (ctype_lower($password[$i])) {
|
||||
$lower = 1;
|
||||
}
|
||||
elseif (ctype_digit($password[$i])) {
|
||||
$digit = 1;
|
||||
}
|
||||
elseif (ctype_punct($password[$i])) {
|
||||
$punct = 1;
|
||||
}
|
||||
}
|
||||
$num = $upper + $lower + $digit + $punct;
|
||||
return $num >= $constraint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript portion.
|
||||
*/
|
||||
function password_policy_constraint_complexity_js($constraint, $uid) {
|
||||
$s = '';
|
||||
$s .= " var i=0;\n";
|
||||
$s .= " var num=0;\n";
|
||||
$s .= " var upper=0;\n";
|
||||
$s .= " var lower=0;\n";
|
||||
$s .= " var digit=0;\n";
|
||||
$s .= " var punct=0;\n";
|
||||
$s .= " var chr=\"\";\n";
|
||||
$s .= " while(i<value.length) {\n";
|
||||
$s .= " chr=value.charAt(i);\n";
|
||||
$s .= " if(chr.toUpperCase() != chr.toLowerCase()) {\n";
|
||||
$s .= " if(chr == chr.toUpperCase()) {\n";
|
||||
$s .= " upper=1;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " else {\n";
|
||||
$s .= " lower=1;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " }\n";
|
||||
$s .= " else if(\"1234567890\".indexOf(chr) != -1) {\n";
|
||||
$s .= " digit=1;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " else if(chr.toUpperCase() == chr.toLowerCase() && \"1234567890\".indexOf(chr) == -1 && chr != ' ') {\n";
|
||||
$s .= " punct=1;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " i++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " num=upper+lower+digit+punct\n";
|
||||
$s .= " if (num<$constraint) {\n";
|
||||
$s .= " strength=\"low\";\n";
|
||||
$s .= " msg.push(translate.constraint_complexity);\n";
|
||||
$s .= " }\n";
|
||||
return $s;
|
||||
}
|
51
modules/password_policy/constraints/constraint_delay.inc
Normal file
51
modules/password_policy/constraints/constraint_delay.inc
Normal file
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Password policy constraint callback to set a minimum delay between password
|
||||
* changes.
|
||||
*
|
||||
* @link http://drupal.org/node/316765
|
||||
* @author David Kent Norman (http://deekayen.net/)
|
||||
*/
|
||||
|
||||
/****************************************************************************/
|
||||
/* Constraint API */
|
||||
/****************************************************************************/
|
||||
|
||||
/**
|
||||
* Description of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_delay_description() {
|
||||
return array('name' => t('Delay'), 'description' => t('Minimum number of hours between password changes.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Error message of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_delay_error($constraint) {
|
||||
return format_plural($constraint, 'Password may only be changed in an hour from the last change.', 'Password may only be changed in @count hours from the last change.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Password validation.
|
||||
*/
|
||||
function password_policy_constraint_delay_validate($password, $constraint, $uid) {
|
||||
$account = user_load($uid);
|
||||
// bypass delay constraint, if account is marked "Force password change on
|
||||
// next login."
|
||||
if ($account->force_password_change) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
$last_change = db_result(db_query_range("SELECT MAX(created) FROM {password_policy_history} WHERE uid = %d", $uid, 0, 1));
|
||||
if (!empty($last_change)) {
|
||||
// Constraint is set in hours, so it gets converted to seconds with *60*60.
|
||||
return time() - ($constraint*60*60) > $last_change;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
function password_policy_constraint_delay_js() {
|
||||
return '';
|
||||
}
|
58
modules/password_policy/constraints/constraint_digit.inc
Normal file
58
modules/password_policy/constraints/constraint_digit.inc
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Password policy constraint callbacks.
|
||||
*/
|
||||
|
||||
/****************************************************************************/
|
||||
/* Constraint API */
|
||||
/****************************************************************************/
|
||||
|
||||
/**
|
||||
* Description of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_digit_description() {
|
||||
return array('name' => t('Digit'), 'description' => t('Password must contain the specified minimum number of digits.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Error message of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_digit_error($constraint) {
|
||||
return format_plural($constraint, 'Password must contain at least one digit.', 'Password must contain at least @count digits.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Password validation.
|
||||
*/
|
||||
function password_policy_constraint_digit_validate($password, $constraint, $uid) {
|
||||
$length = drupal_strlen($password);
|
||||
$num = 0;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (ctype_digit($password[$i]))
|
||||
$num++;
|
||||
}
|
||||
return $num >= $constraint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript portion.
|
||||
*/
|
||||
function password_policy_constraint_digit_js($constraint, $uid) {
|
||||
$s = '';
|
||||
$s .= " var i=0;\n";
|
||||
$s .= " var num=0;\n";
|
||||
$s .= " var chr=\"\";\n";
|
||||
$s .= " while(i<value.length) {\n";
|
||||
$s .= " chr=value.charAt(i);\n";
|
||||
$s .= " if(\"1234567890\".indexOf(chr) != -1) {\n";
|
||||
$s .= " num++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " i++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " if (num<$constraint) {\n";
|
||||
$s .= " strength=\"low\";\n";
|
||||
$s .= " msg.push(translate.constraint_digit);\n";
|
||||
$s .= " }\n";
|
||||
return $s;
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Restrict placement of digits in passwords.
|
||||
*
|
||||
* @link http://drupal.org/node/316768
|
||||
* @author David Kent Norman (http://deekayen.net/)
|
||||
*/
|
||||
|
||||
/****************************************************************************/
|
||||
/* Constraint API */
|
||||
/****************************************************************************/
|
||||
|
||||
/**
|
||||
* Description of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_digit_placement_description() {
|
||||
return array('name' => t('Digit Placement'), 'description' => 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).'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Error message of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_digit_placement_error($constraint) {
|
||||
return t('Password must have a minimum of %numChars %digits in order to place any digits at the start or end of the password.',
|
||||
array('%numChars' => $constraint,
|
||||
'%digits' => format_plural($constraint, t('digit'), t('digits'))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Password validation.
|
||||
*/
|
||||
function password_policy_constraint_digit_placement_validate($password, $constraint, $uid) {
|
||||
$number_of_digits = 0;
|
||||
for ($i=0; $i<10; $i++) {
|
||||
// help string count by sending it a string instead of an int
|
||||
$number_of_digits += substr_count($password, "$i");
|
||||
}
|
||||
if ($number_of_digits < (int)$constraint) {
|
||||
return preg_match("/^(\d+)|(\d+)$/", $password) != 1;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript portion.
|
||||
*/
|
||||
function password_policy_constraint_digit_placement_js($constraint, $uid) {
|
||||
return <<<JSS
|
||||
function substr_count(haystack, needle) {
|
||||
var pos = 0, cnt = 0;
|
||||
|
||||
haystack += '';
|
||||
needle += '';
|
||||
var offset = 0;
|
||||
var length = 0;
|
||||
offset--;
|
||||
|
||||
while ((offset = haystack.indexOf(needle, offset+1)) != -1) {
|
||||
if (length > 0 && (offset+needle.length) > length) {
|
||||
return false;
|
||||
} else {
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
var i=0;
|
||||
var num=0;
|
||||
for (i=0;i<10;i++) {
|
||||
num += substr_count(value, i);
|
||||
}
|
||||
if (num<$constraint && value.match(/^(\d+)|(\d+)$/) != null) {
|
||||
strength="low";
|
||||
msg.push(translate.constraint_digit_placement);
|
||||
}
|
||||
JSS;
|
||||
}
|
66
modules/password_policy/constraints/constraint_history.inc
Normal file
66
modules/password_policy/constraints/constraint_history.inc
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Password policy constraint callbacks.
|
||||
*/
|
||||
|
||||
/****************************************************************************/
|
||||
/* Constraint API */
|
||||
/****************************************************************************/
|
||||
|
||||
/**
|
||||
* Description of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_history_description() {
|
||||
return array('name' => t('History'), 'description' => t('Password must not match any of the user\'s previous X passwords.') . ' <br/><b>' . t('Note: ') . '</b>' . t('This constraint can only compare a new password with the previous passwords recorded since the password policy module was enabled. For example, if the number of previous passwords is set to 3, the module may have only recorded 2 password changes since the module was enabled. If the recorded password history is not large enough to support the constraint history size, the history size for the constraint will be reduced (temporarily during the constraint check) to match the available recorded history. Also note that a history size of 1 means that the user is unable to change their password to their current password. This can be useful in certain situations, but a setting of 2+ will likely be more useful.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Error message of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_history_error($constraint) {
|
||||
return format_plural($constraint, 'Password must not match last password.', 'Password must not match last @count passwords.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Password validation.
|
||||
*/
|
||||
function password_policy_constraint_history_validate($password, $constraint, $uid) {
|
||||
$old_hashes = _password_policy_constraint_history_old_passwords($constraint, $uid);
|
||||
if (module_exists('phpass')) {
|
||||
module_load_include('inc', 'phpass', 'password');
|
||||
$account = new stdClass();
|
||||
foreach ($old_hashes as $old_hash) {
|
||||
$account->pass = $old_hash;
|
||||
if (user_check_password($password, $account)) {
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
$hash = md5($password);
|
||||
return !in_array($hash, $old_hashes);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************/
|
||||
/* Auxiliary */
|
||||
/****************************************************************************/
|
||||
|
||||
/**
|
||||
* Gets old password hashes.
|
||||
*/
|
||||
function _password_policy_constraint_history_old_passwords($constraint, $uid) {
|
||||
$pass = array();
|
||||
if (!empty($uid)) {
|
||||
// note that we specify a limit of the window size, but may not get that if
|
||||
// the history isn't there.
|
||||
$result = db_query("SELECT pass FROM {password_policy_history} WHERE uid =
|
||||
%d ORDER BY created DESC LIMIT %d", $uid, $constraint);
|
||||
while ($row = db_fetch_array($result)) {
|
||||
$pass[] = $row['pass'];
|
||||
}
|
||||
}
|
||||
return $pass;
|
||||
}
|
43
modules/password_policy/constraints/constraint_length.inc
Normal file
43
modules/password_policy/constraints/constraint_length.inc
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?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;
|
||||
}
|
58
modules/password_policy/constraints/constraint_letter.inc
Normal file
58
modules/password_policy/constraints/constraint_letter.inc
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Password policy constraint callbacks.
|
||||
*/
|
||||
|
||||
/****************************************************************************/
|
||||
/* Constraint API */
|
||||
/****************************************************************************/
|
||||
|
||||
/**
|
||||
* Description of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_letter_description() {
|
||||
return array('name' => t('Letter'), 'description' => t('Password must contain the specified minimum number of letters.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Error message of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_letter_error($constraint) {
|
||||
return format_plural($constraint, 'Password must contain at least one letter.', 'Password must contain at least @count letters.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Password validation.
|
||||
*/
|
||||
function password_policy_constraint_letter_validate($password, $constraint, $uid) {
|
||||
$length = drupal_strlen($password);
|
||||
$num = 0;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (ctype_alpha($password[$i]))
|
||||
$num++;
|
||||
}
|
||||
return $num >= $constraint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript portion.
|
||||
*/
|
||||
function password_policy_constraint_letter_js($constraint, $uid) {
|
||||
$s = '';
|
||||
$s .= " var i=0;\n";
|
||||
$s .= " var num=0;\n";
|
||||
$s .= " var chr=\"\";\n";
|
||||
$s .= " while(i<value.length) {\n";
|
||||
$s .= " chr=value.charAt(i);\n";
|
||||
$s .= " if(chr.toUpperCase() != chr.toLowerCase()) {\n";
|
||||
$s .= " num++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " i++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " if (num<$constraint) {\n";
|
||||
$s .= " strength=\"low\";\n";
|
||||
$s .= " msg.push(translate.constraint_letter);\n";
|
||||
$s .= " }\n";
|
||||
return $s;
|
||||
}
|
60
modules/password_policy/constraints/constraint_lowercase.inc
Normal file
60
modules/password_policy/constraints/constraint_lowercase.inc
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?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, $uid) {
|
||||
$length = drupal_strlen($password);
|
||||
$num = 0;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (ctype_lower($password[$i]))
|
||||
$num++;
|
||||
}
|
||||
return $num >= $constraint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript portion.
|
||||
*/
|
||||
function password_policy_constraint_lowercase_js($constraint, $uid) {
|
||||
$s = '';
|
||||
$s .= " var i=0;\n";
|
||||
$s .= " var num=0;\n";
|
||||
$s .= " var chr=\"\";\n";
|
||||
$s .= " while(i<value.length) {\n";
|
||||
$s .= " chr=value.charAt(i);\n";
|
||||
$s .= " if(chr.toUpperCase() != chr.toLowerCase()) {\n";
|
||||
$s .= " if(chr == chr.toLowerCase()) {\n";
|
||||
$s .= " num++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " }\n";
|
||||
$s .= " i++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " if (num<$constraint) {\n";
|
||||
$s .= " strength=\"low\";\n";
|
||||
$s .= " msg.push(translate.constraint_lowercase);\n";
|
||||
$s .= " }\n";
|
||||
return $s;
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Password policy constraint callbacks.
|
||||
*/
|
||||
|
||||
/****************************************************************************/
|
||||
/* Constraint API */
|
||||
/****************************************************************************/
|
||||
|
||||
/**
|
||||
* Description of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_punctuation_description() {
|
||||
return array('name' => t('Punctuation'), 'description' => t('Password must contain the specified minimum number of punctuation (not whitespace or an alphanumeric) characters.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Error message of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_punctuation_error($constraint) {
|
||||
return format_plural($constraint, 'Password must contain at least one punctuation (not whitespace or an alphanumeric) character.', 'Password must contain at least @count punctuation (not whitespace or an alphanumeric) characters.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Password validation.
|
||||
*/
|
||||
function password_policy_constraint_punctuation_validate($password, $constraint, $uid) {
|
||||
$length = drupal_strlen($password);
|
||||
$num = 0;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (ctype_punct($password[$i]))
|
||||
$num++;
|
||||
}
|
||||
return $num >= $constraint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript portion.
|
||||
*/
|
||||
function password_policy_constraint_punctuation_js($constraint, $uid) {
|
||||
$s = '';
|
||||
$s .= " var i=0;\n";
|
||||
$s .= " var num=0;\n";
|
||||
$s .= " var chr=\"\";\n";
|
||||
$s .= " while(i<value.length) {\n";
|
||||
$s .= " chr=value.charAt(i);\n";
|
||||
$s .= " if(chr.toUpperCase() == chr.toLowerCase() && \"1234567890\".indexOf(chr) == -1 && chr != ' ') {\n";
|
||||
$s .= " num++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " i++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " if (num<$constraint) {\n";
|
||||
$s .= " strength=\"low\";\n";
|
||||
$s .= " msg.push(translate.constraint_punctuation);\n";
|
||||
$s .= " }\n";
|
||||
return $s;
|
||||
}
|
60
modules/password_policy/constraints/constraint_uppercase.inc
Normal file
60
modules/password_policy/constraints/constraint_uppercase.inc
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Password policy constraint callbacks.
|
||||
*/
|
||||
|
||||
/****************************************************************************/
|
||||
/* Constraint API */
|
||||
/****************************************************************************/
|
||||
|
||||
/**
|
||||
* Description of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_uppercase_description() {
|
||||
return array('name' => t('Uppercase'), 'description' => t('Password must contain the specified minimum number of uppercase letters.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Error message of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_uppercase_error($constraint) {
|
||||
return format_plural($constraint, 'Password must contain at least one uppercase character.', 'Password must contain at least @count uppercase characters.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Password validation.
|
||||
*/
|
||||
function password_policy_constraint_uppercase_validate($password, $constraint, $uid) {
|
||||
$length = drupal_strlen($password);
|
||||
$num = 0;
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
if (ctype_upper($password[$i]))
|
||||
$num++;
|
||||
}
|
||||
return $num >= $constraint;
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript portion.
|
||||
*/
|
||||
function password_policy_constraint_uppercase_js($constraint, $uid) {
|
||||
$s = '';
|
||||
$s .= " var i=0;\n";
|
||||
$s .= " var num=0;\n";
|
||||
$s .= " var chr=\"\";\n";
|
||||
$s .= " while(i<value.length) {\n";
|
||||
$s .= " chr=value.charAt(i);\n";
|
||||
$s .= " if(chr.toUpperCase() != chr.toLowerCase()) {\n";
|
||||
$s .= " if(chr == chr.toUpperCase()) {\n";
|
||||
$s .= " num++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " }\n";
|
||||
$s .= " i++;\n";
|
||||
$s .= " }\n";
|
||||
$s .= " if (num<$constraint) {\n";
|
||||
$s .= " strength=\"low\";\n";
|
||||
$s .= " msg.push(translate.constraint_uppercase);\n";
|
||||
$s .= " }\n";
|
||||
return $s;
|
||||
}
|
69
modules/password_policy/constraints/constraint_username.inc
Normal file
69
modules/password_policy/constraints/constraint_username.inc
Normal file
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
/**
|
||||
* @file
|
||||
* Password policy constraint callbacks.
|
||||
*/
|
||||
|
||||
/****************************************************************************/
|
||||
/* Constraint API */
|
||||
/****************************************************************************/
|
||||
|
||||
/**
|
||||
* Description of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_username_description() {
|
||||
return array('name' => t('Username'), 'description' => t('Password must not contain the username (case insensitive). Put any positive number to enforce this policy.'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Error message of the constraint.
|
||||
*/
|
||||
function password_policy_constraint_username_error($constraint) {
|
||||
return t('Password must not contain the username.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Password validation.
|
||||
*/
|
||||
function password_policy_constraint_username_validate($password, $constraint, $uid) {
|
||||
$account = user_load(array('uid' => $uid));
|
||||
if ($account->name == '') {
|
||||
return TRUE;
|
||||
}
|
||||
$username_lowercase = drupal_strtolower($account->name);
|
||||
$password_lowercase = drupal_strtolower($password);
|
||||
if ($constraint && (strpos($password_lowercase, $username_lowercase) !== FALSE)) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Javascript portion.
|
||||
*/
|
||||
function password_policy_constraint_username_js($constraint, $uid) {
|
||||
// Add username as JavaScript setting.
|
||||
$account = user_load(array('uid' => $uid));
|
||||
$username = $account->name;
|
||||
if ($username == '') {
|
||||
return '';
|
||||
}
|
||||
$data = array(
|
||||
'password_policy' => array(
|
||||
'username' => $username,
|
||||
),
|
||||
);
|
||||
drupal_add_js($data, 'setting');
|
||||
|
||||
$s = '';
|
||||
if ($constraint) {
|
||||
$s .= " var username=Drupal.settings.password_policy.username;\n";
|
||||
$s .= " var username_lowercase=username.toLowerCase();\n";
|
||||
$s .= " var password_lowercase=value.toLowerCase();\n";
|
||||
$s .= " if (password_lowercase.indexOf(username_lowercase) != -1) {\n";
|
||||
$s .= " strength=\"low\";\n";
|
||||
$s .= " msg.push(translate.constraint_username);\n";
|
||||
$s .= " }\n";
|
||||
}
|
||||
return $s;
|
||||
}
|
Reference in a new issue