sequel_secure_password 0.2.1 → 0.2.2
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.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/lib/sequel_secure_password.rb +16 -1
- data/lib/sequel_secure_password/version.rb +1 -1
- data/sequel_secure_password.gemspec +1 -1
- data/spec/sequel_secure_password_spec.rb +17 -0
- data/spec/spec_helper.rb +11 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8487a3cef20c52b38e950013b4ff5eedf2653171
|
4
|
+
data.tar.gz: 1ca566679bc6e6ffc4548b4f4a4f0affda11cde1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ea0fccc516701add55612477eda482a0f651d3495f0e50d41ea8acef5bbbb2aafa19a8df120881515e363985f4ff240122bf5b17dbea1530051cf1875aa9866
|
7
|
+
data.tar.gz: 9820ae5bc3e94486ae01167061745e104c06963b719d8124975fc28972f0e46bd5790c20c99921b9d8844f35da486eec854d1159181860d451eeeb30ab761de4
|
data/README.md
CHANGED
@@ -22,9 +22,9 @@ Or install it yourself as:
|
|
22
22
|
## Usage
|
23
23
|
|
24
24
|
Plugin should be used in subclasses of `Sequel::Model`. The model should have
|
25
|
-
`password_digest` attribute in database.
|
25
|
+
`password_digest` attribute in database.
|
26
26
|
__Always__ call super in `validate` method of your model, otherwise password
|
27
|
-
validations won't be executed.
|
27
|
+
validations won't be executed.
|
28
28
|
It __does not__ `set_allowed_columns` and mass assignment policy must be managed
|
29
29
|
separately.
|
30
30
|
|
@@ -34,6 +34,11 @@ Example model:
|
|
34
34
|
plugin :secure_password
|
35
35
|
end
|
36
36
|
|
37
|
+
# cost option can be used to change computational complexity of BCrypt
|
38
|
+
class HighCostUser < Sequel::Model
|
39
|
+
plugin :secure_password, cost: 12
|
40
|
+
end
|
41
|
+
|
37
42
|
user = User.new
|
38
43
|
user.password = "foo"
|
39
44
|
user.password_confirmation = "bar"
|
@@ -52,3 +57,7 @@ Example model:
|
|
52
57
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
53
58
|
4. Push to the branch (`git push origin my-new-feature`)
|
54
59
|
5. Create new Pull Request
|
60
|
+
|
61
|
+
## Thanks
|
62
|
+
|
63
|
+
Thanks to [@send](https//:github.com/send) for implementing the `:cost` option.
|
@@ -4,6 +4,21 @@ require "bcrypt"
|
|
4
4
|
module Sequel
|
5
5
|
module Plugins
|
6
6
|
module SecurePassword
|
7
|
+
|
8
|
+
# Configure the plugin by setting the available options. Options:
|
9
|
+
# * :cost - the cost factor when creating password hash. Default:
|
10
|
+
# BCrypt::Engine::DEFAULT_COST(10)
|
11
|
+
def self.configure(model, opts=OPTS)
|
12
|
+
model.instance_eval do
|
13
|
+
@cost = opts[:cost] || BCrypt::Engine::DEFAULT_COST
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
attr_reader :cost
|
19
|
+
Plugins.inherited_instance_variables(self, @cost => nil)
|
20
|
+
end
|
21
|
+
|
7
22
|
module InstanceMethods
|
8
23
|
attr_accessor :password_confirmation
|
9
24
|
attr_reader :password
|
@@ -11,7 +26,7 @@ module Sequel
|
|
11
26
|
def password=(unencrypted)
|
12
27
|
@password = unencrypted
|
13
28
|
unless blank? unencrypted
|
14
|
-
self.password_digest = BCrypt::Password.create(unencrypted)
|
29
|
+
self.password_digest = BCrypt::Password.create(unencrypted, :cost => model.cost)
|
15
30
|
end
|
16
31
|
end
|
17
32
|
|
@@ -22,7 +22,7 @@ EOF
|
|
22
22
|
gem.require_paths = ["lib"]
|
23
23
|
|
24
24
|
gem.add_dependency 'bcrypt-ruby', '~> 3.1.0'
|
25
|
-
gem.add_dependency 'sequel', '~> 4.
|
25
|
+
gem.add_dependency 'sequel', '~> 4.1.0'
|
26
26
|
|
27
27
|
gem.add_development_dependency 'rspec', '~> 2.14.0'
|
28
28
|
gem.add_development_dependency 'rake', '~> 10.0.0'
|
@@ -25,6 +25,13 @@ describe "model using Sequel::Plugins::SecurePassword" do
|
|
25
25
|
it { should_not be_valid }
|
26
26
|
end
|
27
27
|
|
28
|
+
context "having cost within password_digest" do
|
29
|
+
before { user.password = "foo" }
|
30
|
+
it {
|
31
|
+
BCrypt::Password.new(user.password_digest).cost.should be BCrypt::Engine::DEFAULT_COST
|
32
|
+
}
|
33
|
+
end
|
34
|
+
|
28
35
|
context "when password matches confirmation" do
|
29
36
|
before { user.password = user.password_confirmation = "foo" }
|
30
37
|
|
@@ -46,4 +53,14 @@ describe "model using Sequel::Plugins::SecurePassword" do
|
|
46
53
|
end
|
47
54
|
end
|
48
55
|
|
56
|
+
describe "with cost option" do
|
57
|
+
subject(:highcost_user) { HighCostUser.new }
|
58
|
+
context "having cost within password_digest" do
|
59
|
+
before { highcost_user.password = "foo" }
|
60
|
+
it {
|
61
|
+
BCrypt::Password.new(highcost_user.password_digest).cost.should be 12
|
62
|
+
}
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
49
66
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -22,6 +22,17 @@ RSpec.configure do |c|
|
|
22
22
|
end
|
23
23
|
|
24
24
|
User.create_table!
|
25
|
+
|
26
|
+
class HighCostUser < Sequel::Model
|
27
|
+
set_schema do
|
28
|
+
primary_key :id
|
29
|
+
varchar :password_digest
|
30
|
+
end
|
31
|
+
|
32
|
+
plugin :secure_password, :cost => 12
|
33
|
+
end
|
34
|
+
|
35
|
+
HighCostUser.create_table!
|
25
36
|
end
|
26
37
|
|
27
38
|
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.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Lenik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt-ruby
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 4.
|
33
|
+
version: 4.1.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 4.
|
40
|
+
version: 4.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|