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/
6 var shortPass = pwsL10n.short
7 var badPass = pwsL10n.bad
8 var goodPass = pwsL10n.good
9 var strongPass = pwsL10n.strong
12 function passwordStrength(password,username) {
16 if (password.length < 4 ) { return shortPass }
18 //password == username
19 if (password.toLowerCase()==username.toLowerCase()) return badPass
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
28 //password has 3 numbers
29 if (password.match(/(.*[0-9].*[0-9].*[0-9])/)) score += 5
31 //password has 2 sybols
32 if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) score += 5
34 //password has Upper and Lower chars
35 if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) score += 10
37 //password has number and chars
38 if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)) score += 15
40 //password has number and symbol
41 if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)) score += 15
43 //password has char and symbol
44 if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)) score += 15
46 //password is just a nubers or chars
47 if (password.match(/^\w+$/) || password.match(/^\d+$/) ) score -= 10
49 //verifing 0 < score < 100
50 if ( score < 0 ) score = 0
51 if ( score > 100 ) score = 100
53 if (score < 34 ) return badPass
54 if (score < 68 ) return goodPass
59 // checkRepetition(1,'aaaaaaabcbc') = 'abcbc'
60 // checkRepetition(2,'aaaaaaabcbc') = 'aabc'
61 // checkRepetition(2,'aaaaaaabcdbcd') = 'aabcd'
63 function checkRepetition(pLen,str) {
65 for ( i=0; i<str.length ; i++ ) {
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