m2u-upass-admin / WebContent / js / passwordmeter.js @ 20:0163d0f0f9ce
History | View | Annotate | Download (4.62 KB)
1 | 0:ea666cc7880e | hadi | |
---|---|---|---|
2 | |||
3 | var m_strUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; |
||
4 | var m_strLowerCase = "abcdefghijklmnopqrstuvwxyz"; |
||
5 | var m_strNumber = "0123456789"; |
||
6 | var m_strCharacters = "!@#$%^&*?_~"; |
||
7 | |||
8 | |||
9 | function testPassword2() |
||
10 | { |
||
11 | // alert("passwd");
|
||
12 | } |
||
13 | |||
14 | function testPassword(passwd) |
||
15 | { |
||
16 | // alert("testPassword1");
|
||
17 | var intScore = "0"; |
||
18 | var strVerdict = "weak"; |
||
19 | // var strColor = "";
|
||
20 | // var strLog = "";
|
||
21 | |||
22 | // Check password
|
||
23 | var nScore = checkPassword(passwd);
|
||
24 | |||
25 | // Get controls
|
||
26 | // var ctlBar = document.getElementById(strFieldID + "_bar");
|
||
27 | // var ctlText = document.getElementById(strFieldID + "_text");
|
||
28 | // if (!ctlBar || !ctlText)
|
||
29 | // return;
|
||
30 | |||
31 | // Set new width
|
||
32 | // ctlBar.style.width = (nScore*1.25>100)?100:nScore*1.25 + "%";
|
||
33 | |||
34 | // Color and text
|
||
35 | // -- Very Secure
|
||
36 | /*if (nScore >= 90)
|
||
37 | {
|
||
38 | var strText = "Very Secure";
|
||
39 | var strColor = "#0ca908";
|
||
40 | }
|
||
41 | // -- Secure
|
||
42 | else if (nScore >= 80)
|
||
43 | {
|
||
44 | var strText = "Secure";
|
||
45 | vstrColor = "#7ff67c";
|
||
46 | }
|
||
47 | // -- Very Strong
|
||
48 | else
|
||
49 | */
|
||
50 | if (nScore >= 80) |
||
51 | { |
||
52 | strVerdict = "Very Strong";
|
||
53 | strColor = "#008000";
|
||
54 | intScore = "5";
|
||
55 | } |
||
56 | // -- Strong
|
||
57 | else if (nScore >= 60) |
||
58 | { |
||
59 | strVerdict = "Strong";
|
||
60 | strColor = "#006000";
|
||
61 | intScore = "4";
|
||
62 | } |
||
63 | // -- Average
|
||
64 | else if (nScore >= 40) |
||
65 | { |
||
66 | strVerdict = "Average";
|
||
67 | strColor = "#e3cb00";
|
||
68 | intScore = "3";
|
||
69 | } |
||
70 | // -- Weak
|
||
71 | else if (nScore >= 20) |
||
72 | { |
||
73 | strVerdict = "Weak";
|
||
74 | strColor = "#Fe3d1a";
|
||
75 | intScore = "2";
|
||
76 | } |
||
77 | // -- Very Weak
|
||
78 | else
|
||
79 | { |
||
80 | strVerdict = "Very Weak";
|
||
81 | strColor = "#e71a1a";
|
||
82 | intScore = "1";
|
||
83 | } |
||
84 | |||
85 | if(passwd.length == 0) |
||
86 | { |
||
87 | // ctlBar.style.backgroundColor = "";
|
||
88 | document.getElementById('passCheck').innerHTML = (""); |
||
89 | intScore = "0";
|
||
90 | } |
||
91 | else
|
||
92 | { |
||
93 | // ctlBar.style.backgroundColor = strColor;
|
||
94 | document.getElementById('passCheck').innerHTML = (strVerdict);
|
||
95 | |||
96 | } |
||
97 | // alert("testPassword : " + intScore);
|
||
98 | document.getElementById('passCheck').className = "textColor" + intScore; |
||
99 | document.getElementById("passwordStrength").className = "strength" + intScore; |
||
100 | // document.forms.passwordForm.score.value = (intScore)
|
||
101 | // document.forms.passwordForm.verdict.value = (strVerdict)
|
||
102 | // document.forms.passwordForm.matchlog.value = (strLog)
|
||
103 | // document.getElementById('passCheck').innerHTML = (strVerdict + " : " + nScore);
|
||
104 | } |
||
105 | |||
106 | |||
107 | function checkPassword(strPassword) |
||
108 | { |
||
109 | // Reset combination count
|
||
110 | var nScore = 0; |
||
111 | |||
112 | // Password length
|
||
113 | // -- Less than 4 characters
|
||
114 | if (strPassword.length < 5) |
||
115 | { |
||
116 | nScore += 5;
|
||
117 | } |
||
118 | // -- 5 to 7 characters
|
||
119 | else if (strPassword.length > 4 && strPassword.length < 8) |
||
120 | { |
||
121 | nScore += 10;
|
||
122 | } |
||
123 | // -- 8 or more
|
||
124 | else if (strPassword.length > 7) |
||
125 | { |
||
126 | nScore += 25;
|
||
127 | } |
||
128 | |||
129 | // Letters
|
||
130 | var nUpperCount = countContain(strPassword, m_strUpperCase);
|
||
131 | var nLowerCount = countContain(strPassword, m_strLowerCase);
|
||
132 | var nLowerUpperCount = nUpperCount + nLowerCount;
|
||
133 | // -- Letters are all lower case
|
||
134 | if (nUpperCount == 0 && nLowerCount != 0) |
||
135 | { |
||
136 | nScore += 10;
|
||
137 | } |
||
138 | // -- Letters are upper case and lower case
|
||
139 | else if (nUpperCount != 0 && nLowerCount != 0) |
||
140 | { |
||
141 | nScore += 20;
|
||
142 | } |
||
143 | |||
144 | // Numbers
|
||
145 | var nNumberCount = countContain(strPassword, m_strNumber);
|
||
146 | // -- 1 number
|
||
147 | if (nNumberCount == 1) |
||
148 | { |
||
149 | nScore += 10;
|
||
150 | } |
||
151 | // -- 3 or more numbers
|
||
152 | if (nNumberCount >= 3) |
||
153 | { |
||
154 | nScore += 20;
|
||
155 | } |
||
156 | |||
157 | // Characters
|
||
158 | var nCharacterCount = countContain(strPassword, m_strCharacters);
|
||
159 | // -- 1 character
|
||
160 | if (nCharacterCount == 1) |
||
161 | { |
||
162 | nScore += 10;
|
||
163 | } |
||
164 | // -- More than 1 character
|
||
165 | if (nCharacterCount > 1) |
||
166 | { |
||
167 | nScore += 25;
|
||
168 | } |
||
169 | |||
170 | // Bonus
|
||
171 | // -- Letters and numbers
|
||
172 | if (nNumberCount != 0 && nLowerUpperCount != 0) |
||
173 | { |
||
174 | nScore += 2;
|
||
175 | } |
||
176 | // -- Letters, numbers, and characters
|
||
177 | if (nNumberCount != 0 && nLowerUpperCount != 0 && nCharacterCount != 0) |
||
178 | { |
||
179 | nScore += 3;
|
||
180 | } |
||
181 | // -- Mixed case letters, numbers, and characters
|
||
182 | if (nNumberCount != 0 && nUpperCount != 0 && nLowerCount != 0 && nCharacterCount != 0) |
||
183 | { |
||
184 | nScore += 5;
|
||
185 | } |
||
186 | |||
187 | |||
188 | return nScore;
|
||
189 | } |
||
190 | |||
191 | //Checks a string for a list of characters
|
||
192 | function countContain(strPassword, strCheck) |
||
193 | { |
||
194 | // Declare variables
|
||
195 | var nCount = 0; |
||
196 | |||
197 | for (i = 0; i < strPassword.length; i++) |
||
198 | { |
||
199 | if (strCheck.indexOf(strPassword.charAt(i)) > -1) |
||
200 | { |
||
201 | nCount++; |
||
202 | } |
||
203 | } |
||
204 | |||
205 | return nCount;
|
||
206 | } |