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.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +15 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +82 -0
- data/README.rdoc +18 -7
- data/Rakefile +21 -0
- data/app/assets/javascripts/jquery_strength.js +62 -0
- data/app/assets/javascripts/password_strength.js +270 -0
- data/gemfiles/ar_3_2.gemfile +4 -0
- data/gemfiles/ar_4_0.gemfile +4 -0
- data/gemfiles/ar_4_1.gemfile +4 -0
- data/lib/password_strength.rb +1 -0
- data/lib/password_strength/active_record/ar2.rb +5 -1
- data/lib/password_strength/active_record/ar3.rb +5 -2
- data/lib/password_strength/base.rb +28 -0
- data/lib/password_strength/engine.rb +4 -0
- data/lib/password_strength/version.rb +2 -2
- data/password_strength.gemspec +27 -0
- data/support/common.txt +519 -0
- data/test/active_record_test.rb +18 -0
- data/test/jquery_strength_test.html +3 -3
- data/test/jquery_strength_test.js +99 -99
- data/test/password_strength_test.html +2 -2
- data/test/password_strength_test.js +272 -256
- data/test/password_strength_test.rb +21 -9
- data/test/test_helper.rb +3 -2
- metadata +130 -73
- data/javascripts/jquery.strength.js +0 -62
- data/javascripts/password_strength.js +0 -254
data/test/active_record_test.rb
CHANGED
@@ -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/
|
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
|
-
|
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
|
-
|
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
|
-
|
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="../
|
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
|
-
|
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
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
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
|
});
|