password_strength 0.1.6 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/{lib → javascripts}/jquery.strength.js +0 -0
- data/{lib → javascripts}/password_strength.js +0 -0
- data/lib/password_strength.rb +9 -0
- data/lib/password_strength/active_record.rb +1 -1
- data/lib/password_strength/active_record/ar2.rb +1 -1
- data/lib/password_strength/active_record/ar3.rb +1 -1
- data/lib/password_strength/version.rb +2 -2
- data/{lib/password_strength/locales → locales}/en.yml +4 -1
- data/{lib/password_strength/locales → locales}/pt.yml +4 -1
- data/test/active_record_test.rb +7 -0
- data/test/jquery_strength_test.html +2 -2
- data/test/password_strength_test.js +10 -10
- data/test/test_helper.rb +0 -2
- metadata +14 -23
data/README.rdoc
CHANGED
@@ -106,8 +106,8 @@ If you just want to overwrite the callback, you can simple do
|
|
106
106
|
|
107
107
|
Get the files:
|
108
108
|
|
109
|
-
* http://github.com/fnando/password_strength/raw/master/
|
110
|
-
* http://github.com/fnando/password_strength/raw/master/
|
109
|
+
* http://github.com/fnando/password_strength/raw/master/javascripts/password_strength.js
|
110
|
+
* http://github.com/fnando/password_strength/raw/master/javascripts/jquery.strength.js
|
111
111
|
|
112
112
|
= TO-DO
|
113
113
|
|
File without changes
|
File without changes
|
data/lib/password_strength.rb
CHANGED
@@ -28,4 +28,13 @@ module PasswordStrength
|
|
28
28
|
strength.test
|
29
29
|
strength
|
30
30
|
end
|
31
|
+
|
32
|
+
class << self
|
33
|
+
# You can disable PasswordStrength without having to change a single line of code. This is
|
34
|
+
# specially great on development environment.
|
35
|
+
attr_accessor :enabled
|
36
|
+
end
|
37
|
+
|
38
|
+
# Enable verification by default.
|
39
|
+
self.enabled = true
|
31
40
|
end
|
@@ -24,7 +24,7 @@ module PasswordStrength
|
|
24
24
|
|
25
25
|
validates_each(attr_names, options) do |record, attr_name, value|
|
26
26
|
strength = PasswordStrength.test(record.send(options[:with]), value, :exclude => options[:exclude])
|
27
|
-
record.errors.add(attr_name, :too_weak,
|
27
|
+
record.errors.add(attr_name, :too_weak, options) unless PasswordStrength.enabled && strength.valid?(options[:level])
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -7,7 +7,7 @@ module ActiveModel # :nodoc:
|
|
7
7
|
|
8
8
|
def validate_each(record, attribute, value)
|
9
9
|
strength = PasswordStrength.test(record.send(options[:with]), value, :exclude => options[:exclude])
|
10
|
-
record.errors.add(attribute, :too_weak,
|
10
|
+
record.errors.add(attribute, :too_weak, options) unless PasswordStrength.enabled && strength.valid?(options[:level])
|
11
11
|
end
|
12
12
|
|
13
13
|
def check_validity!
|
data/test/active_record_test.rb
CHANGED
@@ -2,6 +2,7 @@ require "test_helper"
|
|
2
2
|
|
3
3
|
class TestActiveRecord < Test::Unit::TestCase
|
4
4
|
def setup
|
5
|
+
PasswordStrength.enabled = true
|
5
6
|
Object.class_eval { remove_const("User") } if defined?(User)
|
6
7
|
load "user.rb"
|
7
8
|
@user = User.new
|
@@ -73,4 +74,10 @@ class TestActiveRecord < Test::Unit::TestCase
|
|
73
74
|
@user.update_attributes :password => "^password with whitespaces 1234ASDF$"
|
74
75
|
assert @user.errors.full_messages.any?
|
75
76
|
end
|
77
|
+
|
78
|
+
def test_ignore_validations_when_password_strength_is_disabled
|
79
|
+
PasswordStrength.enabled = false
|
80
|
+
@user.update_attributes :password => ""
|
81
|
+
assert @user.valid?
|
82
|
+
end
|
76
83
|
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="../
|
18
|
-
<script src="../
|
17
|
+
<script src="../javascripts/password_strength.js" type="text/javascript"></script>
|
18
|
+
<script src="../javascripts/jquery.strength.js" type="text/javascript"></script>
|
19
19
|
</head>
|
20
20
|
<body>
|
21
21
|
|
@@ -31,10 +31,10 @@ new Test.Unit.Runner({
|
|
31
31
|
testWeakStrength: function() { with(this) {
|
32
32
|
strength.status = "weak";
|
33
33
|
assert(strength.isWeak());
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
assert(strength.isValid("weak"));
|
35
|
+
assertEqual(false, strength.isStrong());
|
36
|
+
assertEqual(false, strength.isGood());
|
37
|
+
assertEqual(false, strength.isInvalid());
|
38
38
|
}},
|
39
39
|
|
40
40
|
// Strong strength
|
@@ -247,12 +247,12 @@ new Test.Unit.Runner({
|
|
247
247
|
|
248
248
|
// Exclude option as regular expression
|
249
249
|
testExcludeOptionAsRegularExpression: function() { with(this) {
|
250
|
-
|
251
|
-
|
252
|
-
|
250
|
+
strength.password = "password with whitespaces";
|
251
|
+
strength.exclude = /\s/;
|
252
|
+
strength.test();
|
253
253
|
|
254
|
-
|
255
|
-
|
256
|
-
|
254
|
+
assertEqual("invalid", strength.status);
|
255
|
+
assert(strength.isInvalid());
|
256
|
+
assertEqual(false, strength.isValid());
|
257
257
|
}}
|
258
258
|
});
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,12 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: password_strength
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 6
|
9
|
-
version: 0.1.6
|
4
|
+
version: 0.2.0
|
10
5
|
platform: ruby
|
11
6
|
authors:
|
12
7
|
- Nando Vieira
|
@@ -14,21 +9,19 @@ autorequire:
|
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
11
|
|
17
|
-
date: 2010-
|
12
|
+
date: 2010-07-27 00:00:00 -03:00
|
18
13
|
default_executable:
|
19
14
|
dependencies:
|
20
15
|
- !ruby/object:Gem::Dependency
|
21
16
|
name: activesupport
|
22
|
-
|
23
|
-
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
20
|
requirements:
|
25
21
|
- - ">="
|
26
22
|
- !ruby/object:Gem::Version
|
27
|
-
|
28
|
-
|
29
|
-
version: "0"
|
30
|
-
type: :runtime
|
31
|
-
version_requirements: *id001
|
23
|
+
version: 2.3.5
|
24
|
+
version:
|
32
25
|
description: |
|
33
26
|
Validates the strength of a password according to several rules:
|
34
27
|
|
@@ -50,16 +43,16 @@ extra_rdoc_files:
|
|
50
43
|
files:
|
51
44
|
- CHANGELOG.rdoc
|
52
45
|
- README.rdoc
|
53
|
-
-
|
54
|
-
-
|
46
|
+
- javascripts/jquery.strength.js
|
47
|
+
- javascripts/password_strength.js
|
55
48
|
- lib/password_strength.rb
|
56
49
|
- lib/password_strength/active_record.rb
|
57
50
|
- lib/password_strength/active_record/ar2.rb
|
58
51
|
- lib/password_strength/active_record/ar3.rb
|
59
52
|
- lib/password_strength/base.rb
|
60
|
-
- lib/password_strength/locales/en.yml
|
61
|
-
- lib/password_strength/locales/pt.yml
|
62
53
|
- lib/password_strength/version.rb
|
54
|
+
- locales/en.yml
|
55
|
+
- locales/pt.yml
|
63
56
|
- test/active_record_test.rb
|
64
57
|
- test/jquery-1.4.2.js
|
65
58
|
- test/jquery_strength_test.html
|
@@ -85,20 +78,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
85
78
|
requirements:
|
86
79
|
- - ">="
|
87
80
|
- !ruby/object:Gem::Version
|
88
|
-
segments:
|
89
|
-
- 0
|
90
81
|
version: "0"
|
82
|
+
version:
|
91
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
84
|
requirements:
|
93
85
|
- - ">="
|
94
86
|
- !ruby/object:Gem::Version
|
95
|
-
segments:
|
96
|
-
- 0
|
97
87
|
version: "0"
|
88
|
+
version:
|
98
89
|
requirements: []
|
99
90
|
|
100
91
|
rubyforge_project:
|
101
|
-
rubygems_version: 1.3.
|
92
|
+
rubygems_version: 1.3.5
|
102
93
|
signing_key:
|
103
94
|
specification_version: 3
|
104
95
|
summary: Check password strength against several rules. Includes ActiveRecord support.
|