has_secure_password_argon2 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c990d360c7a1d242ff39c09b18228e22c2246cdfbd36bfbd3da2c7ddb3fe17db
4
+ data.tar.gz: 7c98b094c25dce72089d4cb6697b192a8e61346f2586c4243cc58b4280839d57
5
+ SHA512:
6
+ metadata.gz: 83993960febf56ffc67257c7156d2dcc7733282f54f911f4ea404da63d301cbe9304df1676210a97113ca60e1ff26d65714f3f4d31edb533f4634dcbb5622b61
7
+ data.tar.gz: 4336454d9240e04c3e43be2aed3edf489a57e90c9864097381c049fae17fdfce5a7a588c43dba10aebdbd93ba9f91a796450b950c2da479fc3058e4adff41962
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /test/tmp
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 1.17.2
@@ -0,0 +1,5 @@
1
+ # Changelog
2
+
3
+ ## v1.0.0
4
+
5
+ * Initial version
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at matt@venabl.es. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in has_secure_password_argon2.gemspec
6
+ gemspec
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ has_secure_password_argon2 (1.0.0)
5
+ activerecord (>= 4.2.6)
6
+ activesupport (>= 4.2.6)
7
+ argon2 (~> 2.0)
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ activemodel (5.2.3)
13
+ activesupport (= 5.2.3)
14
+ activerecord (5.2.3)
15
+ activemodel (= 5.2.3)
16
+ activesupport (= 5.2.3)
17
+ arel (>= 9.0)
18
+ activesupport (5.2.3)
19
+ concurrent-ruby (~> 1.0, >= 1.0.2)
20
+ i18n (>= 0.7, < 2)
21
+ minitest (~> 5.1)
22
+ tzinfo (~> 1.1)
23
+ arel (9.0.0)
24
+ argon2 (2.0.2)
25
+ ffi (~> 1.9)
26
+ ffi-compiler (>= 0.1)
27
+ bcrypt (3.1.13)
28
+ concurrent-ruby (1.1.5)
29
+ coveralls (0.8.13)
30
+ json (~> 1.8)
31
+ simplecov (~> 0.11.0)
32
+ term-ansicolor (~> 1.3)
33
+ thor (~> 0.19.1)
34
+ tins (~> 1.6.0)
35
+ docile (1.1.5)
36
+ ffi (1.11.1)
37
+ ffi-compiler (1.0.1)
38
+ ffi (>= 1.0.0)
39
+ rake
40
+ i18n (1.6.0)
41
+ concurrent-ruby (~> 1.0)
42
+ json (1.8.6)
43
+ minitest (5.11.3)
44
+ rake (10.5.0)
45
+ simplecov (0.11.2)
46
+ docile (~> 1.1.0)
47
+ json (~> 1.8)
48
+ simplecov-html (~> 0.10.0)
49
+ simplecov-html (0.10.2)
50
+ sqlite3 (1.4.1)
51
+ term-ansicolor (1.7.1)
52
+ tins (~> 1.0)
53
+ thor (0.19.4)
54
+ thread_safe (0.3.6)
55
+ tins (1.6.0)
56
+ tzinfo (1.2.5)
57
+ thread_safe (~> 0.1)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ bcrypt (~> 3.1)
64
+ bundler (~> 1.17)
65
+ coveralls
66
+ has_secure_password_argon2!
67
+ minitest (~> 5.0)
68
+ rake (~> 10.0)
69
+ simplecov (~> 0.11.2)
70
+ sqlite3 (~> 1.3)
71
+
72
+ BUNDLED WITH
73
+ 1.17.2
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Matt Venables <matt@venabl.es>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # has_secure_password_argon2
2
+
3
+ [![Build Status](https://travis-ci.org/venables/has_secure_password_argon2.svg?branch=master)](https://travis-ci.org/venables/has_secure_password_argon2)
4
+ [![Coverage Status](https://coveralls.io/repos/github/venables/has_secure_password_argon2/badge.svg?branch=master)](https://coveralls.io/github/venables/has_secure_password_argon2?branch=master)
5
+
6
+ Drop-in replacement for Ruby on Rails' `has_secure_password`, but this one uses [argon2](https://en.wikipedia.org/wiki/Argon2) to hash the password.
7
+
8
+ **No code changes necessary.** Just add this gem to your project and your users will be using `argon2`
9
+
10
+ ## Installation
11
+
12
+ Add it to your bundle:
13
+
14
+ ```sh
15
+ bundle add has_secure_password_argon2
16
+ ```
17
+
18
+ Or add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'has_secure_password_argon2'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install has_secure_password_argon2
31
+
32
+ ## Usage
33
+
34
+ Just add this gem to your Gemfile and `has_secure_password` will start to use `argon2` for password hashing.
35
+
36
+ If you already have users authenticating with Rails' version of `has_secure_password`, this gem will automatically upgrade users to `argon2` during their next login. In this case, please leave `bcrypt` installed to support he upgrade process.
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/venables/has_secure_password_argon2. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
41
+
42
+ ## License
43
+
44
+ [MIT](https://opensource.org/licenses/MIT).
45
+
46
+ ## Code of Conduct
47
+
48
+ Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/has_secure_password_argon2/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require 'has_secure_password_argon2/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = 'has_secure_password_argon2'
9
+ spec.version = HasSecurePasswordArgon2::VERSION
10
+ spec.authors = ['Matt Venables']
11
+ spec.email = ['matt@venabl.es']
12
+
13
+ spec.summary = 'Drop-in replacement for has_secure_password that uses argon2'
14
+ spec.homepage = 'https://github.com/venables/has_secure_password_argon2'
15
+ spec.license = 'MIT'
16
+
17
+ if spec.respond_to?(:metadata)
18
+ spec.metadata['homepage_uri'] = spec.homepage
19
+ spec.metadata['source_code_uri'] = 'https://github.com/venables/has_secure_password_argon2'
20
+ spec.metadata['changelog_uri'] = 'https://github.com/venables/has_secure_password_argon2/blob/master/CHANGELOG.md'
21
+ end
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_runtime_dependency 'activerecord', '>= 4.2.6'
31
+ spec.add_runtime_dependency 'activesupport', '>= 4.2.6'
32
+ spec.add_runtime_dependency 'argon2', '~> 2.0'
33
+
34
+ spec.add_development_dependency 'bcrypt', '~> 3.1'
35
+ spec.add_development_dependency 'bundler', '~> 1.17'
36
+ spec.add_development_dependency 'coveralls'
37
+ spec.add_development_dependency 'minitest', '~> 5.0'
38
+ spec.add_development_dependency 'rake', '~> 10.0'
39
+ spec.add_development_dependency 'simplecov', '~> 0.11.2'
40
+ spec.add_development_dependency 'sqlite3', '~> 1.3'
41
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'argon2'
4
+ require 'active_record'
5
+ require 'active_support/all'
6
+ require 'has_secure_password_argon2/version'
7
+
8
+ module HasSecurePasswordArgon2
9
+ extend ActiveSupport::Concern
10
+ class Error < StandardError; end
11
+
12
+ class << self
13
+ attr_accessor :time_cost
14
+ attr_accessor :memory_cost
15
+ attr_accessor :secret
16
+ end
17
+ self.time_cost = 2 # 1..10
18
+ self.memory_cost = 16 # 1..31
19
+
20
+ module ClassMethods
21
+ def has_secure_password(options = {})
22
+ super options
23
+ include InstanceMethodsOnActivation
24
+ end
25
+ end
26
+
27
+ module InstanceMethodsOnActivation
28
+ # Returns +self+ if the password is correct, otherwise +false+.
29
+ #
30
+ # class User < ActiveRecord::Base
31
+ # has_secure_password validations: false
32
+ # end
33
+ #
34
+ # user = User.new(name: 'david', password: 'mUc3m00RsqyRe')
35
+ # user.save
36
+ # user.authenticate('notright') # => false
37
+ # user.authenticate('mUc3m00RsqyRe') # => user
38
+ def authenticate(unencrypted_password)
39
+ if password_digest.start_with?('$argon2')
40
+ Argon2::Password.verify_password(unencrypted_password, password_digest, HasSecurePasswordArgon2.secret) && self
41
+ elsif super(unencrypted_password)
42
+ self.password = hash_argon2_password(unencrypted_password)
43
+ save(validate: false)
44
+ self
45
+ else
46
+ false
47
+ end
48
+ end
49
+
50
+ attr_reader :password
51
+
52
+ # Encrypts the password into the +password_digest+ attribute, only if the
53
+ # new password is not empty.
54
+ #
55
+ # class User < ActiveRecord::Base
56
+ # has_secure_password validations: false
57
+ # end
58
+ #
59
+ # user = User.new
60
+ # user.password = nil
61
+ # user.password_digest # => nil
62
+ # user.password = 'mUc3m00RsqyRe'
63
+ # user.password_digest # => "$2a$10$4LEA7r4YmNHtvlAvHhsYAeZmk/xeUVtMTYqwIvYY76EW5GUqDiP4."
64
+ def password=(unencrypted_password)
65
+ if unencrypted_password.nil?
66
+ self.password_digest = nil
67
+ elsif !unencrypted_password.empty?
68
+ @password = unencrypted_password
69
+ self.password_digest = hash_argon2_password(unencrypted_password)
70
+ end
71
+ end
72
+
73
+ private
74
+
75
+ def hash_argon2_password(unencrypted_password)
76
+ hasher = Argon2::Password.new t_cost: HasSecurePasswordArgon2.time_cost,
77
+ m_cost: HasSecurePasswordArgon2.memory_cost,
78
+ secret: HasSecurePasswordArgon2.secret
79
+
80
+ hasher.create unencrypted_password
81
+ end
82
+ end
83
+ end
84
+
85
+ ActiveRecord::Base.send :include, HasSecurePasswordArgon2
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module HasSecurePasswordArgon2
4
+ VERSION = '1.0.0'
5
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_secure_password_argon2
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Matt Venables
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.2.6
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 4.2.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 4.2.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: argon2
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bcrypt
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.17'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.17'
83
+ - !ruby/object:Gem::Dependency
84
+ name: coveralls
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rake
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '10.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '10.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.11.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.11.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: sqlite3
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '1.3'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '1.3'
153
+ description:
154
+ email:
155
+ - matt@venabl.es
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".travis.yml"
162
+ - CHANGELOG.md
163
+ - CODE_OF_CONDUCT.md
164
+ - Gemfile
165
+ - Gemfile.lock
166
+ - LICENSE.txt
167
+ - README.md
168
+ - Rakefile
169
+ - has_secure_password_argon2.gemspec
170
+ - lib/has_secure_password_argon2.rb
171
+ - lib/has_secure_password_argon2/version.rb
172
+ homepage: https://github.com/venables/has_secure_password_argon2
173
+ licenses:
174
+ - MIT
175
+ metadata:
176
+ homepage_uri: https://github.com/venables/has_secure_password_argon2
177
+ source_code_uri: https://github.com/venables/has_secure_password_argon2
178
+ changelog_uri: https://github.com/venables/has_secure_password_argon2/blob/master/CHANGELOG.md
179
+ post_install_message:
180
+ rdoc_options: []
181
+ require_paths:
182
+ - lib
183
+ required_ruby_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ required_rubygems_version: !ruby/object:Gem::Requirement
189
+ requirements:
190
+ - - ">="
191
+ - !ruby/object:Gem::Version
192
+ version: '0'
193
+ requirements: []
194
+ rubygems_version: 3.0.3
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Drop-in replacement for has_secure_password that uses argon2
198
+ test_files: []