pil 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -47,6 +47,22 @@ You can also instantiate PIL:
47
47
  pil = Pil.new
48
48
  pil.include?( 'areallylongpasswordwithathreeatheend3' ) # => false
49
49
  pil.exclude?( 'areallylongpasswordwithathreeatheend3' ) # => true
50
+
51
+ ## With Rails
52
+
53
+ In your User model:
54
+
55
+ validates_with PasswordInclusionValidator
56
+
57
+ In /app/validators/ create a new class called PasswordInclusionValidator:
58
+
59
+ class PasswordInclusionValidator < ActiveModel::Validator
60
+ def validate(record)
61
+ if Pil.include?(record.password)
62
+ record.errors[:password] << "Password is commonly used. Please choose a different password."
63
+ end
64
+ end
65
+ end
50
66
 
51
67
  ## Contributing to PIL
52
68
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,3 +1,5 @@
1
+ require 'set'
2
+
1
3
  class Pil::PasswordList
2
4
  extend Forwardable
3
5
 
@@ -11,7 +13,7 @@ class Pil::PasswordList
11
13
 
12
14
  def initialize(datafile = DEFAULT_PASSWORD_FILE)
13
15
  @datafile = datafile
14
- @passwords = []
16
+ @passwords = Set.new
15
17
 
16
18
  load_passwords
17
19
  end
@@ -27,7 +29,7 @@ class Pil::PasswordList
27
29
  private
28
30
 
29
31
  def load_passwords
30
- return [] if @datafile.nil?
32
+ raise "Password list cannot be nil" if @datafile.nil?
31
33
 
32
34
  file = File.open(@datafile)
33
35
  file.each_line { |line| @passwords << line.chop }
@@ -0,0 +1,66 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "pil"
8
+ s.version = "0.2.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Chris Cummer"]
12
+ s.date = "2012-12-26"
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
+ s.email = "chriscummer@me.com"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.md"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ "Gemfile",
22
+ "Gemfile.lock",
23
+ "LICENSE.txt",
24
+ "README.md",
25
+ "Rakefile",
26
+ "VERSION",
27
+ "lib/data/passwords.txt",
28
+ "lib/pil.rb",
29
+ "lib/pil/password_list.rb",
30
+ "lib/pil/pil.rb",
31
+ "pil.gemspec",
32
+ "test/helper.rb",
33
+ "test/test_password_list.rb",
34
+ "test/test_pil.rb"
35
+ ]
36
+ s.homepage = "http://github.com/senorprogrammer/pil"
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = "1.8.24"
40
+ s.summary = "The Password Inclusion List"
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
47
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
48
+ s.add_development_dependency(%q<bundler>, ["~> 1.2.0"])
49
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
50
+ s.add_development_dependency(%q<simplecov>, [">= 0"])
51
+ else
52
+ s.add_dependency(%q<shoulda>, [">= 0"])
53
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
54
+ s.add_dependency(%q<bundler>, ["~> 1.2.0"])
55
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
56
+ s.add_dependency(%q<simplecov>, [">= 0"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<shoulda>, [">= 0"])
60
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
61
+ s.add_dependency(%q<bundler>, ["~> 1.2.0"])
62
+ s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
63
+ s.add_dependency(%q<simplecov>, [">= 0"])
64
+ end
65
+ end
66
+
@@ -8,8 +8,12 @@ class PasswordListTest < Test::Unit::TestCase
8
8
  @instance = Pil::PasswordList.new
9
9
  end
10
10
 
11
+ def test_initialize
12
+ assert_raise(RuntimeError) { Pil::PasswordList.new(nil) }
13
+ end
14
+
11
15
  def test_passwords
12
- assert_instance_of(Array, @instance.passwords)
16
+ assert_instance_of(Set, @instance.passwords)
13
17
  end
14
18
 
15
19
  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.1.0
4
+ version: 0.2.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-23 00:00:00.000000000 Z
12
+ date: 2012-12-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: shoulda
@@ -111,6 +111,7 @@ files:
111
111
  - lib/pil.rb
112
112
  - lib/pil/password_list.rb
113
113
  - lib/pil/pil.rb
114
+ - pil.gemspec
114
115
  - test/helper.rb
115
116
  - test/test_password_list.rb
116
117
  - test/test_pil.rb
@@ -129,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
130
  version: '0'
130
131
  segments:
131
132
  - 0
132
- hash: -1597464662707451309
133
+ hash: 2670622847389292681
133
134
  required_rubygems_version: !ruby/object:Gem::Requirement
134
135
  none: false
135
136
  requirements: