Skip to content

Commit

Permalink
Add minimum lowercase rule for password validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
HLeithner committed Mar 18, 2019
1 parent 17d8460 commit 5523a23
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 0 deletions.
11 changes: 11 additions & 0 deletions administrator/components/com_users/config.xml
Expand Up @@ -205,6 +205,17 @@
default="0"
/>

<field
name="minimum_lowercase"
type="integer"
label="COM_USERS_CONFIG_FIELD_MINIMUM_LOWERCASE"
description="COM_USERS_CONFIG_FIELD_MINIMUM_LOWERCASE_DESC"
first="0"
last="98"
step="1"
default="0"
/>

</fieldset>

<fieldset
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/en-GB.com_admin.ini
Expand Up @@ -193,6 +193,8 @@ COM_ADMIN_ZLIB_ENABLED="Zlib Enabled"
; Messages
COM_USERS_MSG_NOT_ENOUGH_INTEGERS_N="Password does not have enough digits. At least %s digits are required."
COM_USERS_MSG_NOT_ENOUGH_INTEGERS_N_1="Password does not have enough digits. At least 1 digit is required."
COM_USERS_MSG_NOT_ENOUGH_LOWERCASE_LETTERS_N="Password does not have enough lowercase characters. At least %s lower case characters are required."
COM_USERS_MSG_NOT_ENOUGH_LOWERCASE_LETTERS_N_1="Password does not have enough lowercase characters. At least 1 lower case character is required."
COM_USERS_MSG_NOT_ENOUGH_SYMBOLS_N="Password does not have enough symbols. At least %s symbols are required."
COM_USERS_MSG_NOT_ENOUGH_SYMBOLS_N_1="Password does not have enough symbols. At least 1 symbol is required."
COM_USERS_MSG_NOT_ENOUGH_UPPERCASE_LETTERS_N="Password does not have enough uppercase characters. At least %s upper case characters are required."
Expand Down
4 changes: 4 additions & 0 deletions administrator/language/en-GB/en-GB.com_users.ini
Expand Up @@ -46,6 +46,8 @@ COM_USERS_CONFIG_FIELD_MAILTOADMIN_DESC="If set to Yes then a notification mail
COM_USERS_CONFIG_FIELD_MAILTOADMIN_LABEL="Send Mail to Administrators"
COM_USERS_CONFIG_FIELD_MINIMUM_INTEGERS="Minimum Integers"
COM_USERS_CONFIG_FIELD_MINIMUM_INTEGERS_DESC="Set the minimum number of integers that must be included in a password."
COM_USERS_CONFIG_FIELD_MINIMUM_LOWERCASE="Minimum Lower Case"
COM_USERS_CONFIG_FIELD_MINIMUM_LOWERCASE_DESC="Set the minimum number of lower case alphabetical characters required for a password."
COM_USERS_CONFIG_FIELD_MINIMUM_PASSWORD_LENGTH="Minimum Length"
COM_USERS_CONFIG_FIELD_MINIMUM_PASSWORD_LENGTH_DESC="Set the minimum length for a password."
COM_USERS_CONFIG_FIELD_MINIMUM_SYMBOLS="Minimum Symbols"
Expand Down Expand Up @@ -228,6 +230,8 @@ COM_USERS_MASS_MAIL="Mass Mail Users"
COM_USERS_MASS_MAIL_DESC="Mass Mail options."
COM_USERS_MSG_NOT_ENOUGH_INTEGERS_N="Password does not have enough digits. At least %s digits are required."
COM_USERS_MSG_NOT_ENOUGH_INTEGERS_N_1="Password does not have enough digits. At least 1 digit is required."
COM_USERS_MSG_NOT_ENOUGH_LOWERCASE_LETTERS_N="Password does not have enough lowercase characters. At least %s lower case characters are required."
COM_USERS_MSG_NOT_ENOUGH_LOWERCASE_LETTERS_N_1="Password does not have enough lowercase characters. At least 1 lower case character is required."
COM_USERS_MSG_NOT_ENOUGH_SYMBOLS_N="Password does not have enough symbols. At least %s symbols are required."
COM_USERS_MSG_NOT_ENOUGH_SYMBOLS_N_1="Password does not have enough symbols. At least 1 symbol is required."
COM_USERS_MSG_NOT_ENOUGH_UPPERCASE_LETTERS_N="Password does not have enough uppercase characters. At least %s upper case characters are required."
Expand Down
2 changes: 2 additions & 0 deletions language/en-GB/en-GB.com_users.ini
Expand Up @@ -53,6 +53,8 @@ COM_USERS_MAIL_SEND_FAILURE_BODY="An error was encountered when sending the user
COM_USERS_MAIL_SEND_FAILURE_SUBJECT="Error sending email"
COM_USERS_MSG_NOT_ENOUGH_INTEGERS_N="Password does not have enough digits. At least %s digits are required."
COM_USERS_MSG_NOT_ENOUGH_INTEGERS_N_1="Password does not have enough digits. At least 1 digit is required."
COM_USERS_MSG_NOT_ENOUGH_LOWERCASE_LETTERS_N="Password does not have enough lowercase characters. At least %s lower case characters are required."
COM_USERS_MSG_NOT_ENOUGH_LOWERCASE_LETTERS_N_1="Password does not have enough lowercase characters. At least 1 lower case character is required."
COM_USERS_MSG_NOT_ENOUGH_SYMBOLS_N="Password does not have enough symbols. At least %s symbols are required."
COM_USERS_MSG_NOT_ENOUGH_SYMBOLS_N_1="Password does not have enough symbols. At least 1 symbol is required."
COM_USERS_MSG_NOT_ENOUGH_UPPERCASE_LETTERS_N="Password does not have enough uppercase characters. At least %s upper case characters are required."
Expand Down
19 changes: 19 additions & 0 deletions libraries/src/Form/Rule/PasswordRule.php
Expand Up @@ -49,6 +49,7 @@ public function test(\SimpleXMLElement $element, $value, $group = null, Registry
$minimumIntegers = isset($element['minimum_integers']) ? (int) $element['minimum_integers'] : 0;
$minimumSymbols = isset($element['minimum_symbols']) ? (int) $element['minimum_symbols'] : 0;
$minimumUppercase = isset($element['minimum_uppercase']) ? (int) $element['minimum_uppercase'] : 0;
$minimumLowercase = isset($element['minimum_lowercase']) ? (int) $element['minimum_lowercase'] : 0;

// If we have parameters from com_users, use those instead.
// Some of these may be empty for legacy reasons.
Expand All @@ -60,13 +61,15 @@ public function test(\SimpleXMLElement $element, $value, $group = null, Registry
$minimumIntegersp = $params->get('minimum_integers');
$minimumSymbolsp = $params->get('minimum_symbols');
$minimumUppercasep = $params->get('minimum_uppercase');
$minimumLowercasep = $params->get('minimum_lowercase');
$meterp = $params->get('meter');
$thresholdp = $params->get('threshold');

empty($minimumLengthp) ? : $minimumLength = (int) $minimumLengthp;
empty($minimumIntegersp) ? : $minimumIntegers = (int) $minimumIntegersp;
empty($minimumSymbolsp) ? : $minimumSymbols = (int) $minimumSymbolsp;
empty($minimumUppercasep) ? : $minimumUppercase = (int) $minimumUppercasep;
empty($minimumLowercasep) ? : $minimumLowercase = (int) $minimumLowercasep;
empty($meterp) ? : $meter = $meterp;
empty($thresholdp) ? : $threshold = $thresholdp;
}
Expand Down Expand Up @@ -154,6 +157,22 @@ public function test(\SimpleXMLElement $element, $value, $group = null, Registry
}
}

// Minimum number of lower case ASCII characters required
if (!empty($minimumLowercase))
{
$nLowercase = preg_match_all('/[A-Z]/', $value, $umatch);

if ($nLowercase < $minimumLowercase)
{
\JFactory::getApplication()->enqueueMessage(
\JText::plural('COM_USERS_MSG_NOT_ENOUGH_LOWERCASE_LETTERS_N', $minimumLowercase),
'warning'
);

$validPassword = false;
}
}

// Minimum length option
if (!empty($minimumLength))
{
Expand Down

0 comments on commit 5523a23

Please sign in to comment.