diff options
author | Bharat Mediratta <bharat@menalto.com> | 2013-02-23 01:09:30 -0500 |
---|---|---|
committer | Bharat Mediratta <bharat@menalto.com> | 2013-02-23 01:09:30 -0500 |
commit | 9d6ed037bb5b346fba900c17ba57b34dae3b6fc8 (patch) | |
tree | 2caddad82bfa6a6ad5f45ea0199c2d0539278026 /modules/user/js | |
parent | 42878556cf38bccfea2b9b38ab2c8dd90d1ebc88 (diff) | |
parent | f95159c0b886a2ff724d6fa9a9315460186b02ef (diff) |
Merge branch 'jquery_190'
Diffstat (limited to 'modules/user/js')
-rw-r--r-- | modules/user/js/password_strength.js | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/modules/user/js/password_strength.js b/modules/user/js/password_strength.js index 2442b8de..5764e332 100644 --- a/modules/user/js/password_strength.js +++ b/modules/user/js/password_strength.js @@ -1,39 +1,38 @@ (function($) { - // Based on the Password Strength Indictor By Benjamin Sterling - // http://benjaminsterling.com/password-strength-indicator-and-generator/ - $.widget("ui.user_password_strength", { - _init: function() { - var self = this; - $(this.element).keyup(function() { - var strength = self.calculateStrength (this.value); - var index = Math.min(Math.floor( strength / 10 ), 10); - $("#g-password-gauge") - .removeAttr('class') - .addClass( "g-password-strength0" ) - .addClass( self.options.classes[ index ] ); - }).after("<div id='g-password-gauge' class='g-password-strength0'></div>"); - }, + // Based on the Password Strength Indictor By Benjamin Sterling + // http://benjaminsterling.com/password-strength-indicator-and-generator/ + $.widget("ui.user_password_strength", { + options: { + classes: ['g-password-strength10', 'g-password-strength20', 'g-password-strength30', + 'g-password-strength40', 'g-password-strength50', 'g-password-strength60', + 'g-password-strength70', 'g-password-strength80', 'g-password-strength90', + 'g-password-strength100'] + }, - calculateStrength: function(value) { - // Factor in the length of the password - var strength = Math.min(5, value.length) * 10 - 20; - // Factor in the number of numbers - strength += Math.min(3, value.length - value.replace(/[0-9]/g,"").length) * 10; - // Factor in the number of non word characters - strength += Math.min(3, value.length - value.replace(/\W/g,"").length) * 15; - // Factor in the number of Upper case letters - strength += Math.min(3, value.length - value.replace(/[A-Z]/g,"").length) * 10; + _init: function() { + var self = this; + $(this.element).keyup(function() { + var strength = self.calculateStrength(this.value); + var index = Math.min(Math.floor(strength / 10), 10); + $("#g-password-gauge") + .removeAttr("class") + .addClass("g-password-strength0") + .addClass(self.options.classes[index]); + }).after("<div id='g-password-gauge' class='g-password-strength0'></div>"); + }, - // Normalizxe between 0 and 100 - return Math.max(0, Math.min(100, strength)); - } - }); - $.extend($.ui.user_password_strength, { - defaults: { - classes : ['g-password-strength10', 'g-password-strength20', 'g-password-strength30', - 'g-password-strength40', 'g-password-strength50', 'g-password-strength60', - 'g-password-strength70',' g-password-strength80',' g-password-strength90', - 'g-password-strength100'] - } - }); - })(jQuery); + calculateStrength: function(value) { + // Factor in the length of the password + var strength = Math.min(5, value.length) * 10 - 20; + // Factor in the number of numbers + strength += Math.min(3, value.length - value.replace(/[0-9]/g,"").length) * 10; + // Factor in the number of non word characters + strength += Math.min(3, value.length - value.replace(/\W/g,"").length) * 15; + // Factor in the number of Upper case letters + strength += Math.min(3, value.length - value.replace(/[A-Z]/g,"").length) * 10; + + // Normalize between 0 and 100 + return Math.max(0, Math.min(100, strength)); + } + }); +})(jQuery); |