sequel_secure_password 0.2.10 → 0.2.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 44647915c05f69c4299469c020fb5b577f83597c
4
- data.tar.gz: 2efcc0094cd07863ec10baa92a4847c8a0ade25c
3
+ metadata.gz: 2e49fcb8f21fc059c0314e08fd91c31f12b29664
4
+ data.tar.gz: 4867077e650776d13903fb2dd5e4af8e1eac373e
5
5
  SHA512:
6
- metadata.gz: dc2f813eae387976c8eb19040f514689d52b594618f4f8c54d91a29f37a39a36bc6994762f4708cdc321f4031fced216c90cf96c27c694a10ae0937cd06ce198
7
- data.tar.gz: 133eb36ec94d8a5b5e5c25c7a4cc76cfa5eab58490e76673f59a8b0bc90803bd3bb83426ca9c7cc538be224d04b029b0439b07ccfa2db7763b826aeacda454d9
6
+ metadata.gz: 8a1587e9ef51a0997539055434fec21d7a1dc5216c78fc552d5cfbfab587277b8e7ed63099fac75a63b53bcef6e298e5a4dd636573eaf2807b4c3571fabf2d65
7
+ data.tar.gz: 1d73d1e5e93854ac28cadf2f89b0b99ff47530f82993201ec16f7a4062f68d8455189b2649980b84f97a9e80b723b8f05d03f86bd83e9a4b86ce86736415bf2d
data/.travis.yml CHANGED
@@ -3,4 +3,6 @@ script: bundle exec rspec
3
3
  rvm:
4
4
  - 1.9.3
5
5
  - 2.0.0
6
+ - 2.1
7
+ - 2.2
6
8
  - jruby-19mode
data/README.md CHANGED
@@ -21,8 +21,7 @@ Or install it yourself as:
21
21
 
22
22
  ## Usage
23
23
 
24
- Plugin should be used in subclasses of `Sequel::Model`. The model should have
25
- `password_digest` attribute in database.
24
+ Plugin should be used in subclasses of `Sequel::Model`.
26
25
  __Always__ call super in `validate` method of your model, otherwise password
27
26
  validations won't be executed.
28
27
  It __does not__ `set_allowed_columns` and mass assignment policy must be managed
@@ -45,6 +44,12 @@ Example model:
45
44
  plugin :secure_password, include_validations: false
46
45
  end
47
46
 
47
+ # digest_column option can be used to use an alternate database column.
48
+ # the default column is "password_digest"
49
+ class UserWithAlternateDigestColumn < Sequel::Model
50
+ plugin :secure_password, digest_column: :password_hash
51
+ end
52
+
48
53
  user = User.new
49
54
  user.password = "foo"
50
55
  user.password_confirmation = "bar"
@@ -17,13 +17,15 @@ module Sequel
17
17
  model.instance_eval do
18
18
  @cost = options.fetch(:cost, BCrypt::Engine::DEFAULT_COST)
19
19
  @include_validations = options.fetch(:include_validations, true)
20
+ @digest_column = options.fetch(:digest_column, :password_digest)
20
21
  end
21
22
  end
22
23
 
23
24
  module ClassMethods
24
- attr_reader :cost, :include_validations
25
+ attr_reader :cost, :include_validations, :digest_column
25
26
  Plugins.inherited_instance_variables(self, :@cost => nil,
26
- :@include_validations => true)
27
+ :@include_validations => true,
28
+ :@digest_column => :password_digest)
27
29
  end
28
30
 
29
31
  module InstanceMethods
@@ -33,12 +35,12 @@ module Sequel
33
35
  def password=(unencrypted)
34
36
  @password = unencrypted
35
37
  unless SecurePassword.blank_string? unencrypted
36
- self.password_digest = BCrypt::Password.create(unencrypted, :cost => model.cost)
38
+ self.send "#{model.digest_column}=", BCrypt::Password.create(unencrypted, :cost => model.cost)
37
39
  end
38
40
  end
39
41
 
40
42
  def authenticate(unencrypted)
41
- if BCrypt::Password.new(password_digest) == unencrypted
43
+ if BCrypt::Password.new(self.send(model.digest_column)) == unencrypted
42
44
  self
43
45
  end
44
46
  end
@@ -47,7 +49,7 @@ module Sequel
47
49
  super
48
50
 
49
51
  if model.include_validations
50
- errors.add :password, 'is not present' if SecurePassword.blank_string?(password_digest)
52
+ errors.add :password, 'is not present' if SecurePassword.blank_string?(self.send(model.digest_column))
51
53
  errors.add :password, 'doesn\'t match confirmation' if password != password_confirmation
52
54
  end
53
55
  end
@@ -1,3 +1,3 @@
1
1
  module SequelSecurePassword
2
- VERSION = "0.2.10"
2
+ VERSION = "0.2.11"
3
3
  end
@@ -52,6 +52,10 @@ describe "model using Sequel::Plugins::SecurePassword" do
52
52
  expect( User.inherited_instance_variables ).to include(:@include_validations)
53
53
  end
54
54
 
55
+ it "has an inherited instance variable :@digest_column" do
56
+ expect( User.inherited_instance_variables ).to include(:@digest_column)
57
+ end
58
+
55
59
  context "when validations are disabled" do
56
60
  subject(:user_without_validations) { UserWithoutValidations.new }
57
61
  before do
@@ -86,4 +90,14 @@ describe "model using Sequel::Plugins::SecurePassword" do
86
90
  }
87
91
  end
88
92
  end
93
+
94
+ describe "with digest column option" do
95
+ subject(:digestcolumn_user) { UserWithAlternateDigestColumn.new }
96
+ context "having an alternate digest column" do
97
+ before { digestcolumn_user.password = "foo" }
98
+ it {
99
+ BCrypt::Password.new(digestcolumn_user.password_hash).should eq "foo"
100
+ }
101
+ end
102
+ end
89
103
  end
data/spec/spec_helper.rb CHANGED
@@ -39,9 +39,19 @@ RSpec.configure do |c|
39
39
  plugin :secure_password, include_validations: false
40
40
  end
41
41
 
42
+ class UserWithAlternateDigestColumn < Sequel::Model
43
+ set_schema do
44
+ primary_key :id
45
+ varchar :password_hash
46
+ end
47
+
48
+ plugin :secure_password, digest_column: :password_hash
49
+ end
50
+
42
51
  User.create_table!
43
52
  HighCostUser.create_table!
44
53
  UserWithoutValidations.create_table!
54
+ UserWithAlternateDigestColumn.create_table!
45
55
  end
46
56
 
47
57
  c.around :each do |example|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sequel_secure_password
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.10
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mateusz Lenik
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-19 00:00:00.000000000 Z
11
+ date: 2015-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bcrypt
@@ -131,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
131
131
  version: '0'
132
132
  requirements: []
133
133
  rubyforge_project:
134
- rubygems_version: 2.2.2
134
+ rubygems_version: 2.4.5
135
135
  signing_key:
136
136
  specification_version: 4
137
137
  summary: Plugin adds BCrypt authentication and password hashing to Sequel models.