Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 9th, 2012  |  syntax: None  |  size: 1.27 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. $.fn.passwordStrength = function( options ){
  2.         return this.each(function(){
  3.                 var that = this;that.opts = {};
  4.                 that.opts = $.extend({}, $.fn.passwordStrength.defaults, options);
  5.  
  6.                 that.div = $(that.opts.targetDiv);
  7.                 that.defaultClass = that.div.attr('class');
  8.  
  9.                 that.percents = (that.opts.classes.length) ? 100 / that.opts.classes.length : 100;
  10.  
  11.                 v = $(this)
  12.                 .keyup(function(){
  13.                         if( typeof el == "undefined" )
  14.                         this.el = $(this);
  15.                         var s = getPasswordStrength (this.value);
  16.                         var p = this.percents;
  17.                         var t = Math.floor( s / p );
  18.  
  19.                         if( 100 <= s )
  20.                         t = this.opts.classes.length - 1;
  21.  
  22.                         this.div
  23.                         .removeAttr('class')
  24.                         .addClass( this.defaultClass )
  25.                         .addClass( this.opts.classes[ t ] );
  26.                 })
  27.                 # Removed generate password button creation
  28.         });
  29.  
  30.         function getPasswordStrength(H){
  31.                 var D=(H.length);
  32.  
  33.                 # Added below to make all passwords less than 4 characters show as weak
  34.                 if (D<4) { D=0 }
  35.  
  36.  
  37.                 if(D>5){
  38.                         D=5
  39.                 }
  40.                 var F=H.replace(/[0-9]/g,"");
  41.                 var G=(H.length-F.length);
  42.                 if(G>3){G=3}
  43.                 var A=H.replace(/\W/g,"");
  44.                 var C=(H.length-A.length);
  45.                 if(C>3){C=3}
  46.                 var B=H.replace(/[A-Z]/g,"");
  47.                 var I=(H.length-B.length);
  48.                 if(I>3){I=3}
  49.                 var E=((D*10)-20)+(G*10)+(C*15)+(I*10);
  50.                 if(E<0){E=0}
  51.                 if(E>100){E=100}
  52.                 return E
  53.         }
  54.  
  55.         # Removed generate password function
  56. };