PageRenderTime 49ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/Gallary/modules/user/js/password_strength.js

https://bitbucket.org/JakePratt/kupcakz.com
JavaScript | 39 lines | 30 code | 2 blank | 7 comment | 0 complexity | 8ad53227aa125b5829fcb9b48b583634 MD5 | raw file
  1. (function($) {
  2. // Based on the Password Strength Indictor By Benjamin Sterling
  3. // http://benjaminsterling.com/password-strength-indicator-and-generator/
  4. $.widget("ui.user_password_strength", {
  5. _init: function() {
  6. var self = this;
  7. $(this.element).keyup(function() {
  8. var strength = self.calculateStrength (this.value);
  9. var index = Math.min(Math.floor( strength / 10 ), 10);
  10. $("#g-password-gauge")
  11. .removeAttr('class')
  12. .addClass( "g-password-strength0" )
  13. .addClass( self.options.classes[ index ] );
  14. }).after("<div id='g-password-gauge' class='g-password-strength0'></div>");
  15. },
  16. calculateStrength: function(value) {
  17. // Factor in the length of the password
  18. var strength = Math.min(5, value.length) * 10 - 20;
  19. // Factor in the number of numbers
  20. strength += Math.min(3, value.length - value.replace(/[0-9]/g,"").length) * 10;
  21. // Factor in the number of non word characters
  22. strength += Math.min(3, value.length - value.replace(/\W/g,"").length) * 15;
  23. // Factor in the number of Upper case letters
  24. strength += Math.min(3, value.length - value.replace(/[A-Z]/g,"").length) * 10;
  25. // Normalizxe between 0 and 100
  26. return Math.max(0, Math.min(100, strength));
  27. }
  28. });
  29. $.extend($.ui.user_password_strength, {
  30. defaults: {
  31. classes : ['g-password-strength10', 'g-password-strength20', 'g-password-strength30',
  32. 'g-password-strength40', 'g-password-strength50', 'g-password-strength60',
  33. 'g-password-strength70',' g-password-strength80',' g-password-strength90',
  34. 'g-password-strength100']
  35. }
  36. });
  37. })(jQuery);