Advertisement
chrishajer

Password strength meter (Gravity Forms 1.6.12)

Mar 24th, 2013
872
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // http://www.gravityhelp.com/forums/topic/password-advanced-field-enable-password-strength-and-minimum-strength#post-182157
  2. // from Gravity Forms version 1.6.12
  3. // wp-content/plugins/gravityforms/js/gravityforms.js starting on line 514
  4. //  
  5. // Password strength meter
  6. function gformPasswordStrength(password1, password2) {
  7.     var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, mismatch = 5, symbolSize = 0, natLog, score;
  8.  
  9.     if(password1.length <=0)
  10.         return "blank";
  11.  
  12.     // password 1 != password 2
  13.     if ( (password1 != password2) && password2.length > 0)
  14.         return "mismatch";
  15.  
  16.     //password < 4
  17.     if ( password1.length < 4 )
  18.         return "short";
  19.  
  20.     if ( password1.match(/[0-9]/) )
  21.         symbolSize +=10;
  22.     if ( password1.match(/[a-z]/) )
  23.         symbolSize +=26;
  24.     if ( password1.match(/[A-Z]/) )
  25.         symbolSize +=26;
  26.     if ( password1.match(/[^a-zA-Z0-9]/) )
  27.         symbolSize +=31;
  28.  
  29.     natLog = Math.log( Math.pow(symbolSize, password1.length) );
  30.     score = natLog / Math.LN2;
  31.  
  32.     if (score < 40 )
  33.         return "bad";
  34.  
  35.     if (score < 56 )
  36.         return "good";
  37.  
  38.     return "strong";
  39.  
  40. }
Advertisement
RAW Paste Data Copied
Advertisement