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" ,
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 ) {
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
222244defaultOptions . common = { } ;
223245defaultOptions . common . minChar = 6 ;
246+ defaultOptions . common . maxChar = 20 ;
224247defaultOptions . common . usernameField = "#username" ;
225248defaultOptions . common . userInputs = [
226249 // Selectors for input fields with user input
@@ -239,7 +262,9 @@ defaultOptions.rules = {};
239262defaultOptions . rules . extra = { } ;
240263defaultOptions . 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} ;
257282defaultOptions . 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
0 commit comments