Skip to content

Commit 1293ebd

Browse files
committed
Increase default security checks for the password
- Activate by default the extra security rules. - Make the invalid chars optional rule configurable.
1 parent faa1e38 commit 1293ebd

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- Thai localization.
66
- Fix typo in German localization.
7+
- Activate by default the extra security rules.
8+
- Make the invalid chars optional rule configurable.
79

810
## 2.1.3
911

OPTIONS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ Let's see the options of each section.
3434
The username field to match a password to, to ensure the user does not use
3535
the same value for their password.
3636

37+
* __invalidCharsRegExp__:
38+
39+
Default: `new RegExp(/[\s,'"]/)` (Regular Expression)
40+
41+
A regular expression object to use to test for banned characters in the
42+
password.
43+
3744
* __userInputs__:
3845

3946
Default: `[]` (Array)

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,20 +174,25 @@ $(document).ready(function () {
174174
```
175175

176176

177-
## Extra security
177+
## Extra restrictions
178178

179179
The plugin comes with two validation rules deactivated by default. One checks
180-
for too many character repetitions, and the other checks the number of
181-
character classes used. An easy way to increase the security of the passwords
182-
is to activate this two rules:
180+
the length of the password and penalizes it if it's too long; and the other
181+
checks if the password contains a banned char, and penalizes it if it does.
182+
183+
You can configure the max length of the password by using the option `maxChar`.
184+
You can also configure the invalid chars by using the option
185+
`invalidCharsRegExp`.
186+
187+
If you need these restrictions you just need to activate this two rules:
183188

184189
```javascript
185190
$(document).ready(function () {
186191
var options = {};
187192
options.rules = {
188193
activated: {
189-
wordTwoCharacterClasses: true,
190-
wordRepetitions: true
194+
wordMaxLength: true,
195+
wordInvalidChar: true
191196
}
192197
};
193198
$(':password').pwstrength(options);

src/options.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ defaultOptions.common = {};
1515
defaultOptions.common.minChar = 6;
1616
defaultOptions.common.maxChar = 20;
1717
defaultOptions.common.usernameField = "#username";
18+
defaultOptions.common.invalidCharsRegExp = new RegExp(/[\s,'"]/);
1819
defaultOptions.common.userInputs = [
1920
// Selectors for input fields with user input
2021
];
@@ -56,8 +57,8 @@ defaultOptions.rules.activated = {
5657
wordInvalidChar: false,
5758
wordSimilarToUsername: true,
5859
wordSequences: true,
59-
wordTwoCharacterClasses: false,
60-
wordRepetitions: false,
60+
wordTwoCharacterClasses: true,
61+
wordRepetitions: true,
6162
wordLowercase: true,
6263
wordUppercase: true,
6364
wordOneNumber: true,

src/rules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ try {
5454
};
5555

5656
validation.wordInvalidChar = function (options, word, score) {
57-
if (word.match(/[\s,',"]/)) {
57+
if (options.common.invalidCharsRegExp.test(word)) {
5858
return score;
5959
}
6060
return 0;

0 commit comments

Comments
 (0)