password_strength 0.3.2 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,4 @@
1
+ # -*- encoding: utf-8 -*-
1
2
  require "test_helper"
2
3
 
3
4
  class TestActiveRecord < Test::Unit::TestCase
@@ -81,4 +82,21 @@ class TestActiveRecord < Test::Unit::TestCase
81
82
  @user.update_attributes :password => ""
82
83
  assert @user.valid?
83
84
  end
85
+
86
+ def test_record_access_from_validator
87
+ tester = Class.new(PasswordStrength::Base) do
88
+ def test
89
+ record.username = 'bar'
90
+ good!
91
+ end
92
+ end
93
+
94
+ User.validates_strength_of :password, :using => tester
95
+ @user.username = "foo"
96
+ @user.password = "foo"
97
+
98
+ assert @user.username, "foo"
99
+ @user.valid?
100
+ assert @user.username, "bar"
101
+ end
84
102
  end
@@ -14,8 +14,8 @@
14
14
  }
15
15
  </style>
16
16
  <script src="jquery-1.4.2.js" type="text/javascript"></script>
17
- <script src="../javascripts/password_strength.js" type="text/javascript"></script>
18
- <script src="../javascripts/jquery.strength.js" type="text/javascript"></script>
17
+ <script src="../app/assets/javascripts/password_strength.js" type="text/javascript"></script>
18
+ <script src="../app/assets/javascripts/jquery_strength.js" type="text/javascript"></script>
19
19
  </head>
20
20
  <body>
21
21
 
@@ -40,4 +40,4 @@
40
40
 
41
41
  <script src="jquery_strength_test.js" type="text/javascript"></script>
42
42
  </body>
43
- </html>
43
+ </html>
@@ -1,105 +1,105 @@
1
1
  new Test.Unit.Runner({
2
- setup: function() {
3
- $("#sample").html('<input type="text" id="username"><input type="text" id="password">');
4
- $("#username").val("johndoe");
5
- $("#password").val("mypass");
6
- },
7
-
8
- teardown: function() {
9
- $("#sample").empty();
10
- },
11
-
12
- // Respond to strength
13
- testRespondToStrength: function() { with(this) {
14
- assertRespondsTo("strength", jQuery);
15
- }},
16
-
17
- // Defaults
18
- testDefaults: function() { with(this) {
19
- $.strength("#username", "#password");
20
- $("#password").trigger("keydown");
21
-
22
- assertEqual(1, $("img.strength").length);
23
- }},
24
-
25
- // Custom callback
26
- testCustomCallback: function() { with(this) {
27
- $.strength("#username", "#password", function(username, password, strength){
28
- assert($(username).is("#username"));
29
- assert($(password).is("#password"));
30
- assert("johndoe", strength.username);
31
- assert("password", strength.password);
32
- assert("weak", strength.status);
33
- });
34
-
35
- $("#password").trigger("keydown");
36
- }},
37
-
38
- // Apply callback when username is triggered
39
- testApplyCallbackWhenUsernameIsTriggered: function() { with(this) {
40
- $.strength("#username", "#password");
41
- $("#username").trigger("keydown");
42
-
43
- assertEqual(1, $("img.strength").length);
44
- }},
45
-
46
- // Apply weak status to image
47
- testApplyWeakStatusToImage: function() { with(this) {
48
- $.strength("#username", "#password");
49
- $("#password").trigger("keydown");
50
-
51
- assertEqual(1, $("img.weak").length);
52
- assertEqual("/images/weak.png", $("img.strength").attr("src"));
53
- }},
54
-
55
- // Apply good status to image
56
- testApplyGoodStatusToImage: function() { with(this) {
57
- $("#password").val("12345asdfg");
58
- $.strength("#username", "#password");
59
- $("#password").trigger("keydown");
60
-
61
- assertEqual(1, $("img.good").length);
62
- assertEqual("/images/good.png", $("img.strength").attr("src"));
63
- }},
64
-
65
- // Apply strong status to image
66
- testApplyStrongStatusToImage: function() { with(this) {
67
- $("#password").val("^P4ssw0rd$");
68
- $.strength("#username", "#password");
69
- $("#password").trigger("keydown");
70
-
71
- assertEqual(1, $("img.strong").length);
72
- assertEqual("/images/strong.png", $("img.strength").attr("src"));
73
- }},
74
-
75
- // Missing username element: use selector as text
76
- testMissingUsernameElementUseSelectorAsText: function() { with(this) {
77
- $("#password").val("^P4ssw0rd$");
78
- $.strength("root", "#password", function(username, password, strength){
79
- assertEqual("root", strength.username);
80
- assertEqual("^P4ssw0rd$", strength.password);
81
- });
82
-
83
- $("#password").trigger("keydown");
84
- }},
85
-
86
- // Missing password element: use selector as text
87
- testMissingPasswordElementUseSelectorAsText: function() { with(this) {
88
- $.strength("#username", "mypass", function(username, password, strength){
89
- assertEqual("johndoe", strength.username);
90
- assertEqual("mypass", strength.password);
91
- });
92
-
93
- $("#username").trigger("keydown");
94
- }},
95
-
96
- // Exclude option as regular expression
97
- testExcludeOption: function() { with(this) {
2
+ setup: function() {
3
+ $("#sample").html('<input type="text" id="username"><input type="text" id="password">');
4
+ $("#username").val("johndoe");
5
+ $("#password").val("mypass");
6
+ },
7
+
8
+ teardown: function() {
9
+ $("#sample").empty();
10
+ },
11
+
12
+ // Respond to strength
13
+ testRespondToStrength: function() { with(this) {
14
+ assertRespondsTo("strength", jQuery);
15
+ }},
16
+
17
+ // Defaults
18
+ testDefaults: function() { with(this) {
19
+ $.strength("#username", "#password");
20
+ $("#password").trigger("keydown");
21
+
22
+ assertEqual(1, $("img.strength").length);
23
+ }},
24
+
25
+ // Custom callback
26
+ testCustomCallback: function() { with(this) {
27
+ $.strength("#username", "#password", function(username, password, strength){
28
+ assert($(username).is("#username"));
29
+ assert($(password).is("#password"));
30
+ assert("johndoe", strength.username);
31
+ assert("password", strength.password);
32
+ assert("weak", strength.status);
33
+ });
34
+
35
+ $("#password").trigger("keydown");
36
+ }},
37
+
38
+ // Apply callback when username is triggered
39
+ testApplyCallbackWhenUsernameIsTriggered: function() { with(this) {
40
+ $.strength("#username", "#password");
41
+ $("#username").trigger("keydown");
42
+
43
+ assertEqual(1, $("img.strength").length);
44
+ }},
45
+
46
+ // Apply weak status to image
47
+ testApplyWeakStatusToImage: function() { with(this) {
48
+ $.strength("#username", "#password");
49
+ $("#password").trigger("keydown");
50
+
51
+ assertEqual(1, $("img.weak").length);
52
+ assertEqual("/images/weak.png", $("img.strength").attr("src"));
53
+ }},
54
+
55
+ // Apply good status to image
56
+ testApplyGoodStatusToImage: function() { with(this) {
57
+ $("#password").val("12345asdfg");
58
+ $.strength("#username", "#password");
59
+ $("#password").trigger("keydown");
60
+
61
+ assertEqual(1, $("img.good").length);
62
+ assertEqual("/images/good.png", $("img.strength").attr("src"));
63
+ }},
64
+
65
+ // Apply strong status to image
66
+ testApplyStrongStatusToImage: function() { with(this) {
67
+ $("#password").val("^P4ssw0rd$");
68
+ $.strength("#username", "#password");
69
+ $("#password").trigger("keydown");
70
+
71
+ assertEqual(1, $("img.strong").length);
72
+ assertEqual("/images/strong.png", $("img.strength").attr("src"));
73
+ }},
74
+
75
+ // Missing username element: use selector as text
76
+ testMissingUsernameElementUseSelectorAsText: function() { with(this) {
77
+ $("#password").val("^P4ssw0rd$");
78
+ $.strength("root", "#password", function(username, password, strength){
79
+ assertEqual("root", strength.username);
80
+ assertEqual("^P4ssw0rd$", strength.password);
81
+ });
82
+
83
+ $("#password").trigger("keydown");
84
+ }},
85
+
86
+ // Missing password element: use selector as text
87
+ testMissingPasswordElementUseSelectorAsText: function() { with(this) {
88
+ $.strength("#username", "mypass", function(username, password, strength){
89
+ assertEqual("johndoe", strength.username);
90
+ assertEqual("mypass", strength.password);
91
+ });
92
+
93
+ $("#username").trigger("keydown");
94
+ }},
95
+
96
+ // Exclude option as regular expression
97
+ testExcludeOption: function() { with(this) {
98
98
  $.strength("#username", "password with whitespaces", {exclude: /\s/}, function(username, password, strength){
99
99
  assertEqual("invalid", strength.status);
100
100
  assert(strength.isInvalid());
101
- });
101
+ });
102
102
 
103
- $("#username").trigger("keydown");
104
- }}
103
+ $("#username").trigger("keydown");
104
+ }}
105
105
  });
@@ -5,7 +5,7 @@
5
5
  <title>JavaScript unit test file</title>
6
6
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7
7
  <script src="jsunittest/jsunittest.js" type="text/javascript"></script>
8
- <script src="../lib/password_strength.js" type="text/javascript"></script>
8
+ <script src="../app/assets/javascripts/password_strength.js" type="text/javascript"></script>
9
9
 
10
10
  <link rel="stylesheet" href="jsunittest/unittest.css" type="text/css" />
11
11
 
@@ -39,4 +39,4 @@
39
39
 
40
40
  <script src="password_strength_test.js" type="text/javascript"></script>
41
41
  </body>
42
- </html>
42
+ </html>
@@ -1,258 +1,274 @@
1
1
  new Test.Unit.Runner({
2
- setup: function() {
3
- strength = new PasswordStrength();
4
- strength.username = "johndoe";
5
- strength.password = "mypass";
6
- },
7
-
8
- teardown: function() {
9
- },
10
-
11
- // Shortcut
12
- testShortcut: function() { with(this) {
13
- strength = PasswordStrength.test("johndoe", "mypass");
14
-
15
- assertEqual("johndoe", strength.username);
16
- assertEqual("mypass", strength.password);
17
- assertNotNull(strength.status);
18
- }},
19
-
20
- // Good strength
21
- testGoodStrength: function() { with(this) {
22
- strength.status = "good";
23
- assert(strength.isGood());
24
- assert(strength.isValid("good"));
25
- assertEqual(false, strength.isWeak());
26
- assertEqual(false, strength.isStrong());
27
- assertEqual(false, strength.isInvalid());
28
- }},
29
-
30
- // Weak strength
31
- testWeakStrength: function() { with(this) {
32
- strength.status = "weak";
33
- assert(strength.isWeak());
34
- assert(strength.isValid("weak"));
35
- assertEqual(false, strength.isStrong());
36
- assertEqual(false, strength.isGood());
37
- assertEqual(false, strength.isInvalid());
38
- }},
39
-
40
- // Strong strength
41
- testStrongStrength: function() { with(this) {
42
- strength.status = "strong";
43
- assert(strength.isStrong());
44
- assert(strength.isValid("strong"));
45
- assert(strength.isValid("good"));
46
- assertEqual(false, strength.isWeak());
47
- assertEqual(false, strength.isGood());
48
- assertEqual(false, strength.isInvalid());
49
- }},
50
-
51
- // Short password
52
- testShortPassword: function() { with(this) {
53
- strength.password = "123";
54
- strength.test();
55
-
56
- assertEqual(0, strength.score);
57
- assertEqual("weak", strength.status);
58
- }},
59
-
60
- // Password equals to username
61
- testPasswordEqualsToUsername: function() { with(this) {
62
- strength.username = "johndoe";
63
- strength.password = "johndoe";
64
- strength.test();
65
-
66
- assertEqual(0, strength.score);
67
- assertEqual("weak", strength.status);
68
- }},
69
-
70
- // Strong password
71
- testStrongPassword: function() { with(this) {
72
- strength.password = "^P4ssw0rd$";
73
- strength.test();
74
-
75
- assertEqual(100, strength.score);
76
- assertEqual("strong", strength.status);
77
- }},
78
-
79
- // Weak password
80
- testWeakPassword: function() { with(this) {
81
- strength.password = "1234567890";
82
- strength.test()
83
- assertEqual("weak", strength.status);
84
-
85
- strength.password = "asdfghjklm";
86
- strength.test();
87
- assertEqual("weak", strength.status);
88
- }},
89
-
90
- // Good password
91
- testGoodPassword: function() { with(this) {
92
- strength.password = "12345asdfg";
93
- strength.test();
94
- assertEqual("good", strength.status);
95
-
96
- strength.password = "12345ASDFG";
97
- strength.test();
98
- assertEqual("good", strength.status);
99
-
100
- strength.password = "12345Aa";
101
- strength.test();
102
- assertEqual("good", strength.status);
103
- }},
104
-
105
- // Penalize password with chars only
106
- testPenalizePasswordWithCharsOnly: function() { with(this) {
107
- strength.password = "abcdef";
108
- assertEqual(-15, strength.scoreFor("only_chars"));
109
- }},
110
-
111
- // Penalize password with numbers only
112
- testPenalizePasswordWithNumbersOnly: function() { with(this) {
113
- strength.password = "12345";
114
- assertEqual(-15, strength.scoreFor("only_numbers"));
115
- }},
116
-
117
- // Penalize password equals to username
118
- testPenalizePasswordEqualsToUsername: function() { with(this) {
119
- strength.username = "johndoe";
120
- strength.password = "johndoe";
121
- assertEqual(-100, strength.scoreFor("username"));
122
- }},
123
-
124
- // Penalize password with username
125
- testPenalizePasswordWithUsername: function() { with(this) {
126
- strength.username = "johndoe";
127
- strength.password = "$1234johndoe^";
128
- assertEqual(-15, strength.scoreFor("username"));
129
- }},
130
-
131
- // Penalize number sequence
132
- testPenalizeNumberSequence: function() { with(this) {
133
- strength.password = "123";
134
- assertEqual(-15, strength.scoreFor("sequences"));
135
-
136
- strength.password = "123123";
137
- assertEqual(-30, strength.scoreFor("sequences"));
138
- }},
139
-
140
- // Penalize letter sequence
141
- testPenalizeLetterSequence: function() { with(this) {
142
- strength.password = "abc";
143
- assertEqual(-15, strength.scoreFor("sequences"));
144
-
145
- strength.password = "abcabc";
146
- assertEqual(-30, strength.scoreFor("sequences"));
147
- }},
148
-
149
- // Penalize number and letter sequence
150
- testPenalizeNumberAndLetterSequence: function() { with(this) {
151
- strength.password = "123abc";
152
- assertEqual(-30, strength.scoreFor("sequences"));
153
-
154
- strength.password = "123abc123abc";
155
- assertEqual(-60, strength.scoreFor("sequences"));
156
- }},
157
-
158
- // Penalize same letter sequence
159
- testPenalizeSameLetterSequence: function() { with(this) {
160
- strength.password = "aaa";
161
- assertEqual(-30, strength.scoreFor("sequences"));
162
- }},
163
-
164
- // Penalize same number sequence
165
- testPenalizeSameNumberSequence: function() { with(this) {
166
- strength.password = "111";
167
- assertEqual(-30, strength.scoreFor("sequences"));
168
- }},
169
-
170
- // Penalize reversed sequence
171
- testPenalizeReversedSequence: function() { with(this) {
172
- strength.password = "cba321";
173
- assertEqual(-30, strength.scoreFor("sequences"));
174
-
175
- strength.password = "cba321cba321";
176
- assertEqual(-60, strength.scoreFor("sequences"));
177
- }},
178
-
179
- // Penalize short password
180
- testPenalizeShortPassword: function() { with(this) {
181
- strength.password = "123";
182
- assertEqual(-100, strength.scoreFor("password_size"));
183
- }},
184
-
185
- // Penalize repetitions
186
- testPenalizeRepetitions: function() { with(this) {
187
- strength.password = "abcdabcdabcd";
188
- assertEqual(-36, strength.scoreFor("repetitions"));
189
- }},
190
-
191
- // Password length
192
- testPasswordLength: function() { with(this) {
193
- strength.password = "12345";
194
- assertEqual(20, strength.scoreFor("password_size"));
195
- }},
196
-
197
- // Password with numbers
198
- testPasswordWithNumbers: function() { with(this) {
199
- strength.password = "123";
200
- assertEqual(5, strength.scoreFor("numbers"));
201
- }},
202
-
203
- // Password with symbols
204
- testPasswordWithSymbols: function() { with(this) {
205
- strength.password = "$!";
206
- assertEqual(5, strength.scoreFor("symbols"));
207
- }},
208
-
209
- // Password with uppercase and lowercase
210
- testPasswordWithUppercaseAndLowercase: function() { with(this) {
211
- strength.password = "aA";
212
- assertEqual(10, strength.scoreFor("uppercase_lowercase"));
213
- }},
214
-
215
- // numbers and chars
216
- testNumbersAndChars: function() { with(this) {
217
- strength.password = "a1";
218
- assertEqual(15, strength.scoreFor("numbers_chars"));
219
- }},
220
-
221
- // Numbers and symbols
222
- testNumbersAndSymbols: function() { with(this) {
223
- strength.password = "1$";
224
- assertEqual(15, strength.scoreFor("numbers_symbols"));
225
- }},
226
-
227
- // Symbols and chars
228
- testSymbolsAndChars: function() { with(this) {
229
- strength.password = "a$";
230
- assertEqual(15, strength.scoreFor("symbols_chars"));
231
- }},
232
-
233
- // Two char repetition
234
- testTwoCharRepetition: function() { with(this) {
235
- assertEqual(3, strength.repetitions("11221122", 2));
236
- }},
237
-
238
- // Three char repetition
239
- testThreeCharRepetition: function() { with(this) {
240
- assertEqual(3, strength.repetitions("123123123", 3));
241
- }},
242
-
243
- // Four char repetition
244
- testFourCharRepetition: function() { with(this) {
245
- assertEqual(4, strength.repetitions("abcdabcdabcd", 4));
246
- }},
247
-
248
- // Exclude option as regular expression
249
- testExcludeOptionAsRegularExpression: function() { with(this) {
250
- strength.password = "password with whitespaces";
251
- strength.exclude = /\s/;
252
- strength.test();
253
-
254
- assertEqual("invalid", strength.status);
255
- assert(strength.isInvalid());
256
- assertEqual(false, strength.isValid());
257
- }}
2
+ setup: function() {
3
+ strength = new PasswordStrength();
4
+ strength.username = "johndoe";
5
+ strength.password = "mypass";
6
+ },
7
+
8
+ teardown: function() {
9
+ },
10
+
11
+ // Shortcut
12
+ testShortcut: function() { with(this) {
13
+ strength = PasswordStrength.test("johndoe", "mypass");
14
+
15
+ assertEqual("johndoe", strength.username);
16
+ assertEqual("mypass", strength.password);
17
+ assertNotNull(strength.status);
18
+ }},
19
+
20
+ // Good strength
21
+ testGoodStrength: function() { with(this) {
22
+ strength.status = "good";
23
+ assert(strength.isGood());
24
+ assert(strength.isValid("good"));
25
+ assertEqual(false, strength.isWeak());
26
+ assertEqual(false, strength.isStrong());
27
+ assertEqual(false, strength.isInvalid());
28
+ }},
29
+
30
+ // Weak strength
31
+ testWeakStrength: function() { with(this) {
32
+ strength.status = "weak";
33
+ assert(strength.isWeak());
34
+ assert(strength.isValid("weak"));
35
+ assertEqual(false, strength.isStrong());
36
+ assertEqual(false, strength.isGood());
37
+ assertEqual(false, strength.isInvalid());
38
+ }},
39
+
40
+ // Strong strength
41
+ testStrongStrength: function() { with(this) {
42
+ strength.status = "strong";
43
+ assert(strength.isStrong());
44
+ assert(strength.isValid("strong"));
45
+ assert(strength.isValid("good"));
46
+ assertEqual(false, strength.isWeak());
47
+ assertEqual(false, strength.isGood());
48
+ assertEqual(false, strength.isInvalid());
49
+ }},
50
+
51
+ // Short password
52
+ testShortPassword: function() { with(this) {
53
+ strength.password = "a";
54
+ strength.test();
55
+
56
+ assertEqual(0, strength.score);
57
+ assertEqual("weak", strength.status);
58
+ }},
59
+
60
+ // Password equals to username
61
+ testPasswordEqualsToUsername: function() { with(this) {
62
+ strength.username = "johndoe";
63
+ strength.password = "johndoe";
64
+ strength.test();
65
+
66
+ assertEqual(0, strength.score);
67
+ assertEqual("weak", strength.status);
68
+ }},
69
+
70
+ // Strong password
71
+ testStrongPassword: function() { with(this) {
72
+ strength.password = "^P4ssw0rd$";
73
+ strength.test();
74
+
75
+ assertEqual(100, strength.score);
76
+ assertEqual("strong", strength.status);
77
+ }},
78
+
79
+ // Weak password
80
+ testWeakPassword: function() { with(this) {
81
+ strength.password = "ytrewq";
82
+ strength.test()
83
+ assertEqual("weak", strength.status);
84
+
85
+ strength.password = "asdfghjklm";
86
+ strength.test();
87
+ assertEqual("weak", strength.status);
88
+ }},
89
+
90
+ // Good password
91
+ testGoodPassword: function() { with(this) {
92
+ strength.password = "12345asdfg";
93
+ strength.test();
94
+ assertEqual("good", strength.status);
95
+
96
+ strength.password = "12345ASDFG";
97
+ strength.test();
98
+ assertEqual("good", strength.status);
99
+
100
+ strength.password = "12345Aa";
101
+ strength.test();
102
+ assertEqual("good", strength.status);
103
+ }},
104
+
105
+ // Penalize password with chars only
106
+ testPenalizePasswordWithCharsOnly: function() { with(this) {
107
+ strength.password = "abcdef";
108
+ assertEqual(-15, strength.scoreFor("only_chars"));
109
+ }},
110
+
111
+ // Penalize password with numbers only
112
+ testPenalizePasswordWithNumbersOnly: function() { with(this) {
113
+ strength.password = "12345";
114
+ assertEqual(-15, strength.scoreFor("only_numbers"));
115
+ }},
116
+
117
+ // Penalize password equals to username
118
+ testPenalizePasswordEqualsToUsername: function() { with(this) {
119
+ strength.username = "johndoe";
120
+ strength.password = "johndoe";
121
+ assertEqual(-100, strength.scoreFor("username"));
122
+ }},
123
+
124
+ // Penalize password with username
125
+ testPenalizePasswordWithUsername: function() { with(this) {
126
+ strength.username = "johndoe";
127
+ strength.password = "$1234johndoe^";
128
+ assertEqual(-15, strength.scoreFor("username"));
129
+ }},
130
+
131
+ // Penalize number sequence
132
+ testPenalizeNumberSequence: function() { with(this) {
133
+ strength.password = "123";
134
+ assertEqual(-15, strength.scoreFor("sequences"));
135
+
136
+ strength.password = "123123";
137
+ assertEqual(-30, strength.scoreFor("sequences"));
138
+ }},
139
+
140
+ // Penalize letter sequence
141
+ testPenalizeLetterSequence: function() { with(this) {
142
+ strength.password = "abc";
143
+ assertEqual(-15, strength.scoreFor("sequences"));
144
+
145
+ strength.password = "abcabc";
146
+ assertEqual(-30, strength.scoreFor("sequences"));
147
+ }},
148
+
149
+ // Penalize number and letter sequence
150
+ testPenalizeNumberAndLetterSequence: function() { with(this) {
151
+ strength.password = "123abc";
152
+ assertEqual(-30, strength.scoreFor("sequences"));
153
+
154
+ strength.password = "123abc123abc";
155
+ assertEqual(-60, strength.scoreFor("sequences"));
156
+ }},
157
+
158
+ // Penalize same letter sequence
159
+ testPenalizeSameLetterSequence: function() { with(this) {
160
+ strength.password = "aaa";
161
+ assertEqual(-30, strength.scoreFor("sequences"));
162
+ }},
163
+
164
+ // Penalize same number sequence
165
+ testPenalizeSameNumberSequence: function() { with(this) {
166
+ strength.password = "111";
167
+ assertEqual(-30, strength.scoreFor("sequences"));
168
+ }},
169
+
170
+ // Penalize reversed sequence
171
+ testPenalizeReversedSequence: function() { with(this) {
172
+ strength.password = "cba321";
173
+ assertEqual(-30, strength.scoreFor("sequences"));
174
+
175
+ strength.password = "cba321cba321";
176
+ assertEqual(-60, strength.scoreFor("sequences"));
177
+ }},
178
+
179
+ // Penalize short password
180
+ testPenalizeShortPassword: function() { with(this) {
181
+ strength.password = "123";
182
+ assertEqual(-100, strength.scoreFor("password_size"));
183
+ }},
184
+
185
+ // Penalize repetitions
186
+ testPenalizeRepetitions: function() { with(this) {
187
+ strength.password = "abcdabcdabcd";
188
+ assertEqual(-36, strength.scoreFor("repetitions"));
189
+ }},
190
+
191
+ // Password length
192
+ testPasswordLength: function() { with(this) {
193
+ strength.password = "12345";
194
+ assertEqual(20, strength.scoreFor("password_size"));
195
+ }},
196
+
197
+ // Password with numbers
198
+ testPasswordWithNumbers: function() { with(this) {
199
+ strength.password = "123";
200
+ assertEqual(5, strength.scoreFor("numbers"));
201
+ }},
202
+
203
+ // Password with symbols
204
+ testPasswordWithSymbols: function() { with(this) {
205
+ strength.password = "$!";
206
+ assertEqual(5, strength.scoreFor("symbols"));
207
+ }},
208
+
209
+ // Password with uppercase and lowercase
210
+ testPasswordWithUppercaseAndLowercase: function() { with(this) {
211
+ strength.password = "aA";
212
+ assertEqual(10, strength.scoreFor("uppercase_lowercase"));
213
+ }},
214
+
215
+ // numbers and chars
216
+ testNumbersAndChars: function() { with(this) {
217
+ strength.password = "a1";
218
+ assertEqual(15, strength.scoreFor("numbers_chars"));
219
+ }},
220
+
221
+ // Numbers and symbols
222
+ testNumbersAndSymbols: function() { with(this) {
223
+ strength.password = "1$";
224
+ assertEqual(15, strength.scoreFor("numbers_symbols"));
225
+ }},
226
+
227
+ // Symbols and chars
228
+ testSymbolsAndChars: function() { with(this) {
229
+ strength.password = "a$";
230
+ assertEqual(15, strength.scoreFor("symbols_chars"));
231
+ }},
232
+
233
+ // Two char repetition
234
+ testTwoCharRepetition: function() { with(this) {
235
+ assertEqual(3, strength.repetitions("11221122", 2));
236
+ }},
237
+
238
+ // Three char repetition
239
+ testThreeCharRepetition: function() { with(this) {
240
+ assertEqual(3, strength.repetitions("123123123", 3));
241
+ }},
242
+
243
+ // Four char repetition
244
+ testFourCharRepetition: function() { with(this) {
245
+ assertEqual(4, strength.repetitions("abcdabcdabcd", 4));
246
+ }},
247
+
248
+ // Exclude option as regular expression
249
+ testExcludeOptionAsRegularExpression: function() { with(this) {
250
+ strength.password = "password with whitespaces";
251
+ strength.exclude = /\s/;
252
+ strength.test();
253
+
254
+ assertEqual("invalid", strength.status);
255
+ assert(strength.isInvalid());
256
+ assertEqual(false, strength.isValid());
257
+ }},
258
+
259
+ // Set common words
260
+ testSetCommonWords: function() { with(this) {
261
+ assert(PasswordStrength.commonWords.length > 500);
262
+ }},
263
+
264
+ // Reject common passwords
265
+ testRejectCommonPasswords: function() { with(this) {
266
+ strength.password = "password with whitespaces";
267
+ strength.exclude = /\s/;
268
+ strength.test();
269
+
270
+ assertEqual("invalid", strength.status);
271
+ assert(strength.isInvalid());
272
+ assertEqual(false, strength.isValid());
273
+ }}
258
274
  });