1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
/*
* --------------------------------------------------------------------
* Simple Password Strength Checker
* by Siddharth S, www.ssiddharth.com, hello@ssiddharth.com
* for Net Tuts, www.net.tutsplus.com
* Version: 1.0, 05.10.2009
* --------------------------------------------------------------------
*/
$(document).ready(function()
{
var strPassword;
var charPassword;
var complexity = $("#complexity");
var rating = $("#rating")
var minPasswordLength = 6;
var baseScore = 0, score = 0;
var num = {};
num.Excess = 0;
num.Upper = 0;
num.Numbers = 0;
num.Symbols = 0;
var bonus = {};
bonus.Excess = 3;
bonus.Upper = 4;
bonus.Numbers = 5;
bonus.Symbols = 5;
bonus.Combo = 0;
bonus.FlatLower = 0;
bonus.FlatNumber = 0;
outputResult();
$("#inputPassword").bind("keyup", checkVal);
function checkVal()
{
init();
if (charPassword.length >= minPasswordLength)
{
baseScore = 50;
analyzeString();
calcComplexity();
}
else
{
baseScore = 0;
}
outputResult();
}
function init()
{
strPassword= $("#inputPassword").val();
charPassword = strPassword.split("");
num.Excess = 0;
num.Upper = 0;
num.Numbers = 0;
num.Symbols = 0;
bonus.Combo = 0;
bonus.FlatLower = 0;
bonus.FlatNumber = 0;
baseScore = 0;
score =0;
}
function analyzeString ()
{
for (i=0; i<charPassword.length;i++)
{
if (charPassword[i].match(/[A-Z]/g)) {num.Upper++;}
if (charPassword[i].match(/[0-9]/g)) {num.Numbers++;}
if (charPassword[i].match(/(.*[!,@,#,$,%,^,&,*,?,_,~])/)) {num.Symbols++;}
}
num.Excess = charPassword.length - minPasswordLength;
if (num.Upper && num.Numbers && num.Symbols)
{
bonus.Combo = 25;
}
else if ((num.Upper && num.Numbers) || (num.Upper && num.Symbols) || (num.Numbers && num.Symbols))
{
bonus.Combo = 15;
}
if (strPassword.match(/^[\sa-z]+$/))
{
bonus.FlatLower = -15;
}
if (strPassword.match(/^[\s0-9]+$/))
{
bonus.FlatNumber = -35;
}
}
function calcComplexity()
{
score = baseScore + (num.Excess*bonus.Excess) + (num.Upper*bonus.Upper) + (num.Numbers*bonus.Numbers) + (num.Symbols*bonus.Symbols) + bonus.Combo + bonus.FlatLower + bonus.FlatNumber;
}
function outputResult()
{
if ($("#inputPassword").val()== "")
{
complexity.html(" ");
rating.removeClass("short weak good strong secure").addClass("default");
}
else if (charPassword.length < minPasswordLength)
{
complexity.html("Too Short");
rating.removeClass("weak good strong secure").addClass("short");
}
else if (score<50)
{
complexity.html("Weak");
rating.removeClass("good strong secure").addClass("weak");
}
else if (score>=50 && score<75)
{
complexity.html("Good");
rating.removeClass("strong secure").addClass("good");
}
else if (score>=75 && score<100)
{
complexity.html("Strong");
rating.removeClass("secure").addClass("strong");
}
else if (score>=100)
{
complexity.html("Secure");
rating.addClass("secure");
}
/*
$("#details").html("Base Score :<span class=\"value\">" + baseScore + "</span>"
+ "<br />Length Bonus :<span class=\"value\">" + (num.Excess*bonus.Excess) + " ["+num.Excess+"x"+bonus.Excess+"]</span> "
+ "<br />Upper case bonus :<span class=\"value\">" + (num.Upper*bonus.Upper) + " ["+num.Upper+"x"+bonus.Upper+"]</span> "
+ "<br />Number Bonus :<span class=\"value\"> " + (num.Numbers*bonus.Numbers) + " ["+num.Numbers+"x"+bonus.Numbers+"]</span>"
+ "<br />Symbol Bonus :<span class=\"value\"> " + (num.Symbols*bonus.Symbols) + " ["+num.Symbols+"x"+bonus.Symbols+"]</span>"
+ "<br />Combination Bonus :<span class=\"value\"> " + bonus.Combo + "</span>"
+ "<br />Lower case only penalty :<span class=\"value\"> " + bonus.FlatLower + "</span>"
+ "<br />Numbers only penalty :<span class=\"value\"> " + bonus.FlatNumber + "</span>"
+ "<br />Total Score:<span class=\"value\"> " + score + "</span>" ); */
}
}
);
|