Skip to content

Commit d6c6916

Browse files
committed
Release v2.1.1
1 parent bf68a99 commit d6c6916

File tree

7 files changed

+96
-21
lines changed

7 files changed

+96
-21
lines changed

CHANGES.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CHANGELOG
22

3-
## 2.1.1dev
3+
## 2.1.1
44

55
- Add missing rule, needed by the `ruleIsMet` method.
66
- Add `wordMaxLength` and `wordInvalidChar` optional rules to the engine.

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "pwstrength-bootstrap",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"homepage": "https://github.com/ablanco/jquery.pwstrength.bootstrap",
55
"authors": [
66
"Alejandro Blanco <alejandro.b.e@gmail.com>"
77
],
88
"description": "jQuery plugin for Twitter Bootstrap that provides rulesets for visualy displaying the quality of a users typed in password.",
99
"main": "dist/pwstrength-bootstrap.js",
1010
"dependencies": {
11-
"jquery": ">=1.7.0",
11+
"jquery": ">=3.0.0",
1212
"bootstrap": ">=2.0.0",
1313
"zxcvbn": ">=4.2.0",
1414
"i18next": ">=2.4.0"

dist/pwstrength-bootstrap.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* jQuery Password Strength plugin for Twitter Bootstrap
3-
* Version: 2.0.8
3+
* Version: 2.1.1
44
*
55
* Copyright (c) 2008-2013 Tane Piper
66
* Copyright (c) 2013 Alejandro Blanco
@@ -105,7 +105,11 @@ try {
105105
return score;
106106
}
107107
return 0;
108-
},
108+
};
109+
110+
validation.wordLengthStaticScore = function (options, word, score) {
111+
return word.length < options.common.minChar ? 0 : score;
112+
};
109113

110114
validation.wordSimilarToUsername = function (options, word, score) {
111115
var username = $(options.common.usernameField).val();
@@ -279,7 +283,7 @@ defaultOptions.rules.activated = {
279283
wordNotEmail: true,
280284
wordMinLength: true,
281285
wordMaxLength: false,
282-
wordInvalidChar: true,
286+
wordInvalidChar: false,
283287
wordSimilarToUsername: true,
284288
wordSequences: true,
285289
wordTwoCharacterClasses: false,
@@ -707,7 +711,9 @@ var methods = {};
707711
verdictLevel = verdictText[1];
708712
verdictText = verdictText[0];
709713

710-
if (options.common.debug) { console.log(score + ' - ' + verdictText); }
714+
if (options.common.debug) {
715+
console.log(score + ' - ' + verdictText);
716+
}
711717

712718
if ($.isFunction(options.common.onKeyUp)) {
713719
options.common.onKeyUp(event, {
@@ -728,7 +734,7 @@ var methods = {};
728734
callback;
729735

730736
callback = function () {
731-
var newWord = $el.val();
737+
var newWord = $el.val();
732738

733739
if (newWord !== word) {
734740
onKeyUp(event);
@@ -811,6 +817,26 @@ var methods = {};
811817
applyToAll.call(this, rule, "activated", active);
812818
};
813819

820+
methods.ruleIsMet = function (rule) {
821+
if ($.isFunction(rulesEngine.validation[rule])) {
822+
if (rule === "wordLength") {
823+
rule = "wordLengthStaticScore";
824+
}
825+
826+
var rulesMetCnt = 0;
827+
828+
this.each(function (idx, el) {
829+
var options = $(el).data("pwstrength-bootstrap");
830+
831+
rulesMetCnt += rulesEngine.validation[rule](options, $(el).val(), 1);
832+
});
833+
834+
return (rulesMetCnt === this.length);
835+
}
836+
837+
$.error("Rule " + rule + " does not exist on jQuery.pwstrength-bootstrap.validation");
838+
};
839+
814840
$.fn.pwstrength = function (method) {
815841
var result;
816842

dist/pwstrength-bootstrap.min.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/pwstrength-bootstrap.min.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/pwstrength.js

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
* jQuery Password Strength plugin for Twitter Bootstrap
3-
* Version: 2.0.8
3+
* Version: 2.1.1
44
*
55
* Copyright (c) 2008-2013 Tane Piper
66
* Copyright (c) 2013 Alejandro Blanco
@@ -19,7 +19,9 @@ var i18n = {};
1919
'use strict';
2020

2121
i18n.fallback = {
22-
"wordLength": "Your password is too short",
22+
"wordMinLength": "Your password is too short",
23+
"wordMaxLength": "Your password is too long",
24+
"wordInvalidChar": "Your password contains an invalid character",
2325
"wordNotEmail": "Do not use your email as your password",
2426
"wordSimilarToUsername": "Your password cannot contain your username",
2527
"wordTwoCharacterClasses": "Use different character classes",
@@ -80,7 +82,7 @@ try {
8082
return 0;
8183
};
8284

83-
validation.wordLength = function (options, word, score) {
85+
validation.wordMinLength = function (options, word, score) {
8486
var wordlen = word.length,
8587
lenScore = Math.pow(wordlen, options.rules.raisePower);
8688
if (wordlen < options.common.minChar) {
@@ -89,6 +91,26 @@ try {
8991
return lenScore;
9092
};
9193

94+
validation.wordMaxLength = function (options, word, score) {
95+
var wordlen = word.length,
96+
lenScore = Math.pow(wordlen, options.rules.raisePower);
97+
if (wordlen > options.common.maxChar) {
98+
return score;
99+
}
100+
return lenScore;
101+
};
102+
103+
validation.wordInvalidChar = function (options, word, score) {
104+
if (word.match(/[\s,',"]/)) {
105+
return score;
106+
}
107+
return 0;
108+
};
109+
110+
validation.wordLengthStaticScore = function (options, word, score) {
111+
return word.length < options.common.minChar ? 0 : score;
112+
};
113+
92114
validation.wordSimilarToUsername = function (options, word, score) {
93115
var username = $(options.common.usernameField).val();
94116
if (username && word.toLowerCase().match(username.replace(/[\-\[\]\/\{\}\(\)\*\+\=\?\:\.\\\^\$\|\!\,]/g, "\\$&").toLowerCase())) {
@@ -221,6 +243,7 @@ var defaultOptions = {};
221243

222244
defaultOptions.common = {};
223245
defaultOptions.common.minChar = 6;
246+
defaultOptions.common.maxChar = 20;
224247
defaultOptions.common.usernameField = "#username";
225248
defaultOptions.common.userInputs = [
226249
// Selectors for input fields with user input
@@ -239,7 +262,9 @@ defaultOptions.rules = {};
239262
defaultOptions.rules.extra = {};
240263
defaultOptions.rules.scores = {
241264
wordNotEmail: -100,
242-
wordLength: -50,
265+
wordMinLength: -50,
266+
wordMaxLength: -50,
267+
wordInvalidChar: -100,
243268
wordSimilarToUsername: -100,
244269
wordSequences: -20,
245270
wordTwoCharacterClasses: 2,
@@ -256,7 +281,9 @@ defaultOptions.rules.scores = {
256281
};
257282
defaultOptions.rules.activated = {
258283
wordNotEmail: true,
259-
wordLength: true,
284+
wordMinLength: true,
285+
wordMaxLength: false,
286+
wordInvalidChar: false,
260287
wordSimilarToUsername: true,
261288
wordSequences: true,
262289
wordTwoCharacterClasses: false,
@@ -684,7 +711,9 @@ var methods = {};
684711
verdictLevel = verdictText[1];
685712
verdictText = verdictText[0];
686713

687-
if (options.common.debug) { console.log(score + ' - ' + verdictText); }
714+
if (options.common.debug) {
715+
console.log(score + ' - ' + verdictText);
716+
}
688717

689718
if ($.isFunction(options.common.onKeyUp)) {
690719
options.common.onKeyUp(event, {
@@ -705,7 +734,7 @@ var methods = {};
705734
callback;
706735

707736
callback = function () {
708-
var newWord = $el.val();
737+
var newWord = $el.val();
709738

710739
if (newWord !== word) {
711740
onKeyUp(event);
@@ -788,6 +817,26 @@ var methods = {};
788817
applyToAll.call(this, rule, "activated", active);
789818
};
790819

820+
methods.ruleIsMet = function (rule) {
821+
if ($.isFunction(rulesEngine.validation[rule])) {
822+
if (rule === "wordLength") {
823+
rule = "wordLengthStaticScore";
824+
}
825+
826+
var rulesMetCnt = 0;
827+
828+
this.each(function (idx, el) {
829+
var options = $(el).data("pwstrength-bootstrap");
830+
831+
rulesMetCnt += rulesEngine.validation[rule](options, $(el).val(), 1);
832+
});
833+
834+
return (rulesMetCnt === this.length);
835+
}
836+
837+
$.error("Rule " + rule + " does not exist on jQuery.pwstrength-bootstrap.validation");
838+
};
839+
791840
$.fn.pwstrength = function (method) {
792841
var result;
793842

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pwstrength-bootstrap",
3-
"version": "2.1.0",
3+
"version": "2.1.1",
44
"description": "jQuery plugin for Twitter Bootstrap that provides rulesets for visualy displaying the quality of a users typed in password.",
55
"author": "Alejandro Blanco <alejandro.b.e@gmail.com>",
66
"homepage": "https://github.com/ablanco/jquery.pwstrength.bootstrap",

0 commit comments

Comments
 (0)