Index: branches/1.0.x/inc/js/passwordStrengthMeter.js =================================================================== diff -u -N -r14759 -r15169 --- branches/1.0.x/inc/js/passwordStrengthMeter.js (.../passwordStrengthMeter.js) (revision 14759) +++ branches/1.0.x/inc/js/passwordStrengthMeter.js (.../passwordStrengthMeter.js) (revision 15169) @@ -1,138 +1,138 @@ -function PasswordStrengthMeter($settings) { - this.inputSelector = ''; - - this.phrases = { - 'short': 'Too Short Password', - 'bad': 'Week; Use letters & numbers', - 'good': 'Medium; Use special characters', - 'strong': 'Strong Password' - }; - - this.cssClasses = { - 'short': 'meterFail', - 'bad': 'meterWarn', - 'good': 'meterGood', - 'strong': 'meterExcel' - }; - - $.extend(true, this, $settings); - - var $me = this; - - $(document).ready( - function() { - $($me.inputSelector).keyup( - function($e) { - $($me.inputSelector + '_strength') - .html( $me.getStrengthHTML( $(this).val() ) ) - .show(); - } - ); - } - ); -} - -PasswordStrengthMeter.prototype.getStrength = function (password) { - var score = 0; - - // password < 4 - if (password.length < 4) { - return 'short'; - } - - // password length - score += password.length * 4; - score += parseInt( this.checkRepetition(1, password).length - password.length ); - score += parseInt( this.checkRepetition(2, password).length - password.length ); - score += parseInt( this.checkRepetition(3, password).length - password.length ); - score += parseInt( this.checkRepetition(4, password).length - password.length ); - - // password has 3 numbers - if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) { - score += 5; - } - - // password has 2 symbols - if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) { - score += 5; - } - - // password has Upper and Lower chars - if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) { - score += 10; - } - - // password has number and chars - if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) { - score += 15; - } - // - // password has number and symbol - if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)) { - score += 15; - } - - // password has char and symbol - if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)) { - score += 15; - } - - // password is just a nubers or chars - if (password.match(/^\w+$/) || password.match(/^\d+$/)) { - score -= 10; - } - - // verifying 0 < score < 100 - if (score < 0) { - score = 0; - } - - if (score > 100) { - score = 100; - } - - if (score < 34) { - return 'bad'; - } - - if (score < 68) { - return 'good'; - } - - return 'strong'; -} - -PasswordStrengthMeter.prototype.getStrengthHTML = function (password) { - var $strength = this.getStrength(password), - $css_class = this.cssClasses[$strength], - $phrase = this.phrases[$strength]; - - return ' ' + $phrase + ''; -} - -PasswordStrengthMeter.prototype.checkRepetition = function(pLen, str) { - var res = "", - repeated = true; - - for (i = 0; i < str.length; i++) { - repeated = true; - - for (j = 0; j < pLen && (j + i + pLen) < str.length; j++) { - repeated = repeated && (str.charAt(j + i) == str.charAt(j + i + pLen)); - } - - if (j < pLen) { - repeated = false; - } - - if (repeated) { - i += pLen - 1; - repeated = false; - } - else { - res += str.charAt(i); - } - } - - return res; +function PasswordStrengthMeter($settings) { + this.inputSelector = ''; + + this.phrases = { + 'short': 'Too Short Password', + 'bad': 'Week; Use letters & numbers', + 'good': 'Medium; Use special characters', + 'strong': 'Strong Password' + }; + + this.cssClasses = { + 'short': 'meterFail', + 'bad': 'meterWarn', + 'good': 'meterGood', + 'strong': 'meterExcel' + }; + + $.extend(true, this, $settings); + + var $me = this; + + $(document).ready( + function() { + $($me.inputSelector).keyup( + function($e) { + $($me.inputSelector + '_strength') + .html( $me.getStrengthHTML( $(this).val() ) ) + .show(); + } + ); + } + ); +} + +PasswordStrengthMeter.prototype.getStrength = function (password) { + var score = 0; + + // password < 4 + if (password.length < 4) { + return 'short'; + } + + // password length + score += password.length * 4; + score += parseInt( this.checkRepetition(1, password).length - password.length ); + score += parseInt( this.checkRepetition(2, password).length - password.length ); + score += parseInt( this.checkRepetition(3, password).length - password.length ); + score += parseInt( this.checkRepetition(4, password).length - password.length ); + + // password has 3 numbers + if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) { + score += 5; + } + + // password has 2 symbols + if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) { + score += 5; + } + + // password has Upper and Lower chars + if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) { + score += 10; + } + + // password has number and chars + if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) { + score += 15; + } + // + // password has number and symbol + if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)) { + score += 15; + } + + // password has char and symbol + if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)) { + score += 15; + } + + // password is just a nubers or chars + if (password.match(/^\w+$/) || password.match(/^\d+$/)) { + score -= 10; + } + + // verifying 0 < score < 100 + if (score < 0) { + score = 0; + } + + if (score > 100) { + score = 100; + } + + if (score < 34) { + return 'bad'; + } + + if (score < 68) { + return 'good'; + } + + return 'strong'; +} + +PasswordStrengthMeter.prototype.getStrengthHTML = function (password) { + var $strength = this.getStrength(password), + $css_class = this.cssClasses[$strength], + $phrase = this.phrases[$strength]; + + return ' ' + $phrase + ''; +} + +PasswordStrengthMeter.prototype.checkRepetition = function(pLen, str) { + var res = "", + repeated = true; + + for (i = 0; i < str.length; i++) { + repeated = true; + + for (j = 0; j < pLen && (j + i + pLen) < str.length; j++) { + repeated = repeated && (str.charAt(j + i) == str.charAt(j + i + pLen)); + } + + if (j < pLen) { + repeated = false; + } + + if (repeated) { + i += pLen - 1; + repeated = false; + } + else { + res += str.charAt(i); + } + } + + return res; } \ No newline at end of file