home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Blogs / wordpress2.6.exe / wordpress2.6 / wp-admin / js / password-strength-meter.js < prev    next >
Encoding:
JavaScript  |  2008-03-15  |  2.5 KB  |  81 lines

  1. // Password strength meter
  2. // This jQuery plugin is written by firas kassem [2007.04.05]
  3. // Firas Kassem  phiras.wordpress.com || phiras at gmail {dot} com
  4. // for more information : http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/
  5.  
  6. var shortPass = pwsL10n.short
  7. var badPass = pwsL10n.bad
  8. var goodPass = pwsL10n.good
  9. var strongPass = pwsL10n.strong
  10.  
  11.  
  12. function passwordStrength(password,username) {
  13.     score = 0
  14.  
  15.     //password < 4
  16.     if (password.length < 4 ) { return shortPass }
  17.  
  18.     //password == username
  19.     if (password.toLowerCase()==username.toLowerCase()) return badPass
  20.  
  21.     //password length
  22.     score += password.length * 4
  23.     score += ( checkRepetition(1,password).length - password.length ) * 1
  24.     score += ( checkRepetition(2,password).length - password.length ) * 1
  25.     score += ( checkRepetition(3,password).length - password.length ) * 1
  26.     score += ( checkRepetition(4,password).length - password.length ) * 1
  27.  
  28.     //password has 3 numbers
  29.     if (password.match(/(.*[0-9].*[0-9].*[0-9])/))  score += 5
  30.  
  31.     //password has 2 sybols
  32.     if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5
  33.  
  34.     //password has Upper and Lower chars
  35.     if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))  score += 10
  36.  
  37.     //password has number and chars
  38.     if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/))  score += 15
  39.     //
  40.     //password has number and symbol
  41.     if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/))  score += 15
  42.  
  43.     //password has char and symbol
  44.     if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/))  score += 15
  45.  
  46.     //password is just a nubers or chars
  47.     if (password.match(/^\w+$/) || password.match(/^\d+$/) )  score -= 10
  48.  
  49.     //verifing 0 < score < 100
  50.     if ( score < 0 )  score = 0
  51.     if ( score > 100 )  score = 100
  52.  
  53.     if (score < 34 )  return badPass
  54.     if (score < 68 )  return goodPass
  55.     return strongPass
  56. }
  57.  
  58.  
  59. // checkRepetition(1,'aaaaaaabcbc')   = 'abcbc'
  60. // checkRepetition(2,'aaaaaaabcbc')   = 'aabc'
  61. // checkRepetition(2,'aaaaaaabcdbcd') = 'aabcd'
  62.  
  63. function checkRepetition(pLen,str) {
  64.     res = ""
  65.     for ( i=0; i<str.length ; i++ ) {
  66.         repeated=true
  67.         for (j=0;j < pLen && (j+i+pLen) < str.length;j++)
  68.             repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen))
  69.         if (j<pLen) repeated=false
  70.         if (repeated) {
  71.             i+=pLen-1
  72.             repeated=false
  73.         }
  74.         else {
  75.             res+=str.charAt(i)
  76.         }
  77.     }
  78.     return res
  79. }
  80.  
  81.