pil 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +11 -7
- data/VERSION +1 -1
- data/lib/pil/password_list.rb +5 -13
- data/pil.gemspec +2 -2
- data/test/test_password_list.rb +2 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -47,19 +47,23 @@ You can also instantiate PIL:
|
|
47
47
|
pil = Pil.new
|
48
48
|
pil.include?( 'areallylongpasswordwithathreeatheend3' ) # => false
|
49
49
|
pil.exclude?( 'areallylongpasswordwithathreeatheend3' ) # => true
|
50
|
-
|
50
|
+
|
51
51
|
## With Rails
|
52
52
|
|
53
53
|
In your User model:
|
54
54
|
|
55
|
-
|
55
|
+
validates :password, uncommon: true
|
56
|
+
|
57
|
+
If you prefer your own error message (ie: for localization):
|
58
|
+
|
59
|
+
validates :password, uncommon: { error_message: "Password is too common." }
|
56
60
|
|
57
|
-
In /app/validators/ create a new class called
|
61
|
+
In /app/validators/ create a new class called UncommonValidator:
|
58
62
|
|
59
|
-
class
|
60
|
-
def
|
61
|
-
if Pil.include?(
|
62
|
-
|
63
|
+
class UncommonValidator < ActiveModel::EachValidator
|
64
|
+
def validate_each(object, attribute, value)
|
65
|
+
if Pil.include?(value)
|
66
|
+
object.errors[attribute] << (options[:error_message] || "Password is commonly used. Please choose a different password.")
|
63
67
|
end
|
64
68
|
end
|
65
69
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/lib/pil/password_list.rb
CHANGED
@@ -10,16 +10,10 @@ class Pil::PasswordList
|
|
10
10
|
# ------------------------------ Instance Methods ------------------------------
|
11
11
|
|
12
12
|
def_delegator :@passwords, :count, :count
|
13
|
+
def_delegator :@passwords, :include?, :include?
|
13
14
|
|
14
15
|
def initialize(datafile = DEFAULT_PASSWORD_FILE)
|
15
|
-
|
16
|
-
@passwords = Set.new
|
17
|
-
|
18
|
-
load_passwords
|
19
|
-
end
|
20
|
-
|
21
|
-
def include?(password)
|
22
|
-
@passwords.include?(password)
|
16
|
+
load_passwords(datafile)
|
23
17
|
end
|
24
18
|
|
25
19
|
def exclude?(password)
|
@@ -28,10 +22,8 @@ class Pil::PasswordList
|
|
28
22
|
|
29
23
|
private
|
30
24
|
|
31
|
-
def load_passwords
|
32
|
-
raise "Password list cannot be nil" if
|
33
|
-
|
34
|
-
file = File.open(@datafile)
|
35
|
-
file.each_line { |line| @passwords << line.chop }
|
25
|
+
def load_passwords(datafile)
|
26
|
+
raise "Password list cannot be nil" if datafile.nil?
|
27
|
+
File.open(datafile) { |file| @passwords = Set.new(file.readlines.each(&:chop!)) }
|
36
28
|
end
|
37
29
|
end
|
data/pil.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "pil"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Chris Cummer"]
|
12
|
-
s.date = "2012-12-
|
12
|
+
s.date = "2012-12-28"
|
13
13
|
s.description = "Checks a given plaintext password against an inclusion list of common passwords. Returns TRUE if the user's password is in the list; FALSE if it isn't."
|
14
14
|
s.email = "chriscummer@me.com"
|
15
15
|
s.extra_rdoc_files = [
|
data/test/test_password_list.rb
CHANGED
@@ -13,7 +13,8 @@ class PasswordListTest < Test::Unit::TestCase
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_passwords
|
16
|
-
|
16
|
+
assert_respond_to(@instance.passwords, :count)
|
17
|
+
assert_respond_to(@instance.passwords, :include?)
|
17
18
|
end
|
18
19
|
|
19
20
|
def test_include?
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: shoulda
|
@@ -130,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
130
|
version: '0'
|
131
131
|
segments:
|
132
132
|
- 0
|
133
|
-
hash:
|
133
|
+
hash: -767269175845970462
|
134
134
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
135
|
none: false
|
136
136
|
requirements:
|