sequel_secure_password 0.2.14 → 0.2.15
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/.travis.yml +3 -0
- data/lib/sequel/plugins/secure_password.rb +64 -0
- data/lib/sequel_secure_password.rb +1 -65
- data/lib/sequel_secure_password/version.rb +1 -1
- data/sequel_secure_password.gemspec +1 -1
- data/spec/spec_helper.rb +30 -33
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 49f624d3a015d6565492278ec5e5bd249beb3cb0
|
4
|
+
data.tar.gz: 2b94d0cf5df97b0ac4d68214c22f434f09d19ef0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '006899fdf56b909c44588d474d94584ba03165548f00d97c2f3eba284903b04a8b917421f2b39cafddf63de11fbff1ebc30cb8c9d730457ddb9766cc8daeff87'
|
7
|
+
data.tar.gz: 37026898cb3ece6eb738ca4b0aee0d08aacbd3e59620dbf21a0aa4624abf7c26a21ec70fbc67441506826f25d151e0bf1c5d0c98f8ab0bd406884b2d6dc33a39
|
data/.travis.yml
CHANGED
@@ -0,0 +1,64 @@
|
|
1
|
+
require "sequel"
|
2
|
+
require "bcrypt"
|
3
|
+
|
4
|
+
module Sequel
|
5
|
+
module Plugins
|
6
|
+
module SecurePassword
|
7
|
+
def self.blank_string?(string)
|
8
|
+
string.nil? or string =~ /\A\s*\z/
|
9
|
+
end
|
10
|
+
|
11
|
+
# Configure the plugin by setting the available options. Options:
|
12
|
+
# * :cost - the cost factor when creating password hash. Default:
|
13
|
+
# BCrypt::Engine::DEFAULT_COST(10)
|
14
|
+
# * :include_validations - when set to false, password present and
|
15
|
+
# confirmation validations won't be included. Default: true
|
16
|
+
def self.configure(model, options = {})
|
17
|
+
model.instance_eval do
|
18
|
+
@cost = options.fetch(:cost, BCrypt::Engine.cost)
|
19
|
+
@include_validations = options.fetch(:include_validations, true)
|
20
|
+
@digest_column = options.fetch(:digest_column, :password_digest)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
module ClassMethods
|
25
|
+
attr_reader :cost, :include_validations, :digest_column
|
26
|
+
|
27
|
+
# NOTE: nil as a value means that the value of the instance variable
|
28
|
+
# will be assigned as is in the subclass.
|
29
|
+
Plugins.inherited_instance_variables(self, :@cost => nil,
|
30
|
+
:@include_validations => nil,
|
31
|
+
:@digest_column => nil)
|
32
|
+
end
|
33
|
+
|
34
|
+
module InstanceMethods
|
35
|
+
attr_accessor :password_confirmation
|
36
|
+
attr_reader :password
|
37
|
+
|
38
|
+
def password=(unencrypted)
|
39
|
+
@password = unencrypted
|
40
|
+
|
41
|
+
unless SecurePassword.blank_string?(unencrypted)
|
42
|
+
self.send "#{model.digest_column}=", BCrypt::Password.create(unencrypted, :cost => model.cost)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def authenticate(unencrypted)
|
47
|
+
if BCrypt::Password.new(self.send(model.digest_column)) == unencrypted
|
48
|
+
self
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def validate
|
53
|
+
super
|
54
|
+
|
55
|
+
if model.include_validations
|
56
|
+
errors.add :password, 'is not present' if SecurePassword.blank_string?(self.send(model.digest_column))
|
57
|
+
errors.add :password, 'doesn\'t match confirmation' if password != password_confirmation
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -1,65 +1 @@
|
|
1
|
-
require
|
2
|
-
require "sequel"
|
3
|
-
require "bcrypt"
|
4
|
-
|
5
|
-
module Sequel
|
6
|
-
module Plugins
|
7
|
-
module SecurePassword
|
8
|
-
def self.blank_string?(string)
|
9
|
-
string.nil? or string =~ /\A\s*\z/
|
10
|
-
end
|
11
|
-
|
12
|
-
# Configure the plugin by setting the available options. Options:
|
13
|
-
# * :cost - the cost factor when creating password hash. Default:
|
14
|
-
# BCrypt::Engine::DEFAULT_COST(10)
|
15
|
-
# * :include_validations - when set to false, password present and
|
16
|
-
# confirmation validations won't be included. Default: true
|
17
|
-
def self.configure(model, options = {})
|
18
|
-
model.instance_eval do
|
19
|
-
@cost = options.fetch(:cost, BCrypt::Engine.cost)
|
20
|
-
@include_validations = options.fetch(:include_validations, true)
|
21
|
-
@digest_column = options.fetch(:digest_column, :password_digest)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
module ClassMethods
|
26
|
-
attr_reader :cost, :include_validations, :digest_column
|
27
|
-
|
28
|
-
# NOTE: nil as a value means that the value of the instance variable
|
29
|
-
# will be assigned as is in the subclass.
|
30
|
-
Plugins.inherited_instance_variables(self, :@cost => nil,
|
31
|
-
:@include_validations => nil,
|
32
|
-
:@digest_column => nil)
|
33
|
-
end
|
34
|
-
|
35
|
-
module InstanceMethods
|
36
|
-
attr_accessor :password_confirmation
|
37
|
-
attr_reader :password
|
38
|
-
|
39
|
-
def password=(unencrypted)
|
40
|
-
@password = unencrypted
|
41
|
-
|
42
|
-
unless SecurePassword.blank_string?(unencrypted)
|
43
|
-
self.send "#{model.digest_column}=", BCrypt::Password.create(unencrypted, :cost => model.cost)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def authenticate(unencrypted)
|
48
|
-
if BCrypt::Password.new(self.send(model.digest_column)) == unencrypted
|
49
|
-
self
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def validate
|
54
|
-
super
|
55
|
-
|
56
|
-
if model.include_validations
|
57
|
-
errors.add :password, 'is not present' if SecurePassword.blank_string?(self.send(model.digest_column))
|
58
|
-
errors.add :password, 'doesn\'t match confirmation' if password != password_confirmation
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
1
|
+
require 'sequel/plugins/secure_password'
|
@@ -23,7 +23,7 @@ EOF
|
|
23
23
|
gem.require_paths = ["lib"]
|
24
24
|
|
25
25
|
gem.add_dependency 'bcrypt', ['>= 3.1', '< 4.0']
|
26
|
-
gem.add_dependency 'sequel', ['>= 4.1.0', '<
|
26
|
+
gem.add_dependency 'sequel', ['>= 4.1.0', '< 6.0']
|
27
27
|
|
28
28
|
gem.add_development_dependency 'rspec', '~> 3.0'
|
29
29
|
gem.add_development_dependency 'rake', '~> 12'
|
data/spec/spec_helper.rb
CHANGED
@@ -3,60 +3,57 @@ require 'bundler'
|
|
3
3
|
Bundler.setup
|
4
4
|
|
5
5
|
require 'sequel'
|
6
|
-
require '
|
6
|
+
require 'sequel/extensions/migration'
|
7
|
+
require 'sequel/plugins/secure_password'
|
7
8
|
|
8
|
-
adapter = RUBY_PLATFORM ==
|
9
|
+
adapter = RUBY_PLATFORM == 'java' ? 'jdbc:sqlite::memory:' : 'sqlite:/'
|
9
10
|
|
10
11
|
RSpec.configure do |c|
|
11
12
|
c.before :suite do
|
12
|
-
Sequel::Model.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
Sequel::Model.db = Sequel.connect(adapter)
|
14
|
+
|
15
|
+
Sequel.migration do
|
16
|
+
up do
|
17
|
+
create_table(:users) do
|
18
|
+
primary_key :id
|
19
|
+
varchar :password_digest
|
20
|
+
end
|
21
|
+
|
22
|
+
create_table(:high_cost_users) do
|
23
|
+
primary_key :id
|
24
|
+
varchar :password_digest
|
25
|
+
end
|
26
|
+
|
27
|
+
create_table(:user_without_validations) do
|
28
|
+
primary_key :id
|
29
|
+
varchar :password_digest
|
30
|
+
end
|
31
|
+
|
32
|
+
create_table(:user_with_alternate_digest_columns) do
|
33
|
+
primary_key :id
|
34
|
+
varchar :password_hash
|
35
|
+
end
|
19
36
|
end
|
37
|
+
end.apply(Sequel::Model.db, :up)
|
20
38
|
|
39
|
+
class User < Sequel::Model
|
21
40
|
plugin :secure_password
|
22
41
|
end
|
23
42
|
|
24
43
|
class HighCostUser < Sequel::Model
|
25
|
-
set_schema do
|
26
|
-
primary_key :id
|
27
|
-
varchar :password_digest
|
28
|
-
end
|
29
|
-
|
30
44
|
plugin :secure_password, cost: 12
|
31
45
|
end
|
32
46
|
|
33
47
|
class UserWithoutValidations < Sequel::Model
|
34
|
-
set_schema do
|
35
|
-
primary_key :id
|
36
|
-
varchar :password_digest
|
37
|
-
end
|
38
|
-
|
39
48
|
plugin :secure_password, include_validations: false
|
40
49
|
end
|
41
50
|
|
42
51
|
class UserWithAlternateDigestColumn < Sequel::Model
|
43
|
-
set_schema do
|
44
|
-
primary_key :id
|
45
|
-
varchar :password_hash
|
46
|
-
end
|
47
|
-
|
48
52
|
plugin :secure_password, digest_column: :password_hash
|
49
53
|
end
|
50
|
-
|
51
|
-
User.create_table!
|
52
|
-
HighCostUser.create_table!
|
53
|
-
UserWithoutValidations.create_table!
|
54
|
-
UserWithAlternateDigestColumn.create_table!
|
55
54
|
end
|
56
55
|
|
57
|
-
c.around
|
58
|
-
Sequel::Model.db.transaction(:
|
56
|
+
c.around(:each) do |example|
|
57
|
+
Sequel::Model.db.transaction(rollback: :always) { example.run }
|
59
58
|
end
|
60
59
|
end
|
61
|
-
|
62
|
-
|
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.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mateusz Lenik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bcrypt
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
version: 4.1.0
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '6.0'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -49,7 +49,7 @@ dependencies:
|
|
49
49
|
version: 4.1.0
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '6.0'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: rspec
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- LICENSE.txt
|
127
127
|
- README.md
|
128
128
|
- Rakefile
|
129
|
+
- lib/sequel/plugins/secure_password.rb
|
129
130
|
- lib/sequel_secure_password.rb
|
130
131
|
- lib/sequel_secure_password/version.rb
|
131
132
|
- sequel_secure_password.gemspec
|
@@ -151,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
152
|
version: '0'
|
152
153
|
requirements: []
|
153
154
|
rubyforge_project:
|
154
|
-
rubygems_version: 2.6.
|
155
|
+
rubygems_version: 2.6.14
|
155
156
|
signing_key:
|
156
157
|
specification_version: 4
|
157
158
|
summary: Plugin adds BCrypt authentication and password hashing to Sequel models.
|