passwd 0.2.0 → 0.3.0

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.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +10 -17
  3. data/.travis.yml +3 -11
  4. data/Gemfile +3 -1
  5. data/LICENSE +21 -0
  6. data/README.md +39 -53
  7. data/Rakefile +6 -6
  8. data/bin/console +7 -0
  9. data/bin/setup +8 -0
  10. data/lib/generators/passwd/install/USAGE +5 -0
  11. data/lib/generators/passwd/install/install_generator.rb +10 -0
  12. data/lib/generators/passwd/install/templates/passwd.rb +27 -0
  13. data/lib/passwd.rb +33 -15
  14. data/lib/passwd/config.rb +29 -0
  15. data/lib/passwd/errors.rb +2 -7
  16. data/lib/passwd/rails/action_controller_ext.rb +77 -0
  17. data/lib/passwd/rails/active_record_ext.rb +37 -0
  18. data/lib/passwd/railtie.rb +5 -6
  19. data/lib/passwd/version.rb +2 -2
  20. data/passwd.gemspec +13 -14
  21. metadata +22 -156
  22. data/.coveralls.yml +0 -1
  23. data/CHANGELOG.md +0 -35
  24. data/LICENSE.txt +0 -23
  25. data/example/.gitignore +0 -16
  26. data/example/Gemfile +0 -25
  27. data/example/README.rdoc +0 -28
  28. data/example/Rakefile +0 -6
  29. data/example/app/assets/images/.keep +0 -0
  30. data/example/app/assets/javascripts/application.js +0 -16
  31. data/example/app/assets/stylesheets/application.css +0 -16
  32. data/example/app/controllers/application_controller.rb +0 -10
  33. data/example/app/controllers/concerns/.keep +0 -0
  34. data/example/app/controllers/profiles_controller.rb +0 -28
  35. data/example/app/controllers/root_controller.rb +0 -5
  36. data/example/app/controllers/sessions_controller.rb +0 -29
  37. data/example/app/helpers/application_helper.rb +0 -2
  38. data/example/app/mailers/.keep +0 -0
  39. data/example/app/models/.keep +0 -0
  40. data/example/app/models/concerns/.keep +0 -0
  41. data/example/app/models/user.rb +0 -4
  42. data/example/app/views/layouts/application.html.erb +0 -15
  43. data/example/app/views/profiles/edit.html.erb +0 -14
  44. data/example/app/views/profiles/show.html.erb +0 -12
  45. data/example/app/views/root/index.html.erb +0 -5
  46. data/example/app/views/sessions/new.html.erb +0 -6
  47. data/example/bin/bundle +0 -3
  48. data/example/bin/rails +0 -4
  49. data/example/bin/rake +0 -4
  50. data/example/config.ru +0 -4
  51. data/example/config/application.rb +0 -40
  52. data/example/config/boot.rb +0 -4
  53. data/example/config/database.yml +0 -26
  54. data/example/config/environment.rb +0 -5
  55. data/example/config/environments/development.rb +0 -37
  56. data/example/config/environments/production.rb +0 -78
  57. data/example/config/environments/test.rb +0 -39
  58. data/example/config/initializers/assets.rb +0 -8
  59. data/example/config/initializers/backtrace_silencers.rb +0 -7
  60. data/example/config/initializers/cookies_serializer.rb +0 -3
  61. data/example/config/initializers/filter_parameter_logging.rb +0 -4
  62. data/example/config/initializers/inflections.rb +0 -16
  63. data/example/config/initializers/mime_types.rb +0 -4
  64. data/example/config/initializers/passwd.rb +0 -41
  65. data/example/config/initializers/session_store.rb +0 -3
  66. data/example/config/initializers/wrap_parameters.rb +0 -14
  67. data/example/config/locales/en.yml +0 -23
  68. data/example/config/routes.rb +0 -16
  69. data/example/config/secrets.yml +0 -22
  70. data/example/db/migrate/20141122165914_create_users.rb +0 -13
  71. data/example/db/schema.rb +0 -25
  72. data/example/db/seeds.rb +0 -7
  73. data/example/lib/assets/.keep +0 -0
  74. data/example/lib/tasks/.keep +0 -0
  75. data/example/lib/tasks/user.rake +0 -12
  76. data/example/log/.keep +0 -0
  77. data/example/public/404.html +0 -67
  78. data/example/public/422.html +0 -67
  79. data/example/public/500.html +0 -66
  80. data/example/public/favicon.ico +0 -0
  81. data/example/public/robots.txt +0 -5
  82. data/example/vendor/assets/javascripts/.keep +0 -0
  83. data/example/vendor/assets/stylesheets/.keep +0 -0
  84. data/lib/generators/passwd/config_generator.rb +0 -13
  85. data/lib/generators/passwd/templates/passwd_config.rb +0 -41
  86. data/lib/passwd/action_controller_ext.rb +0 -48
  87. data/lib/passwd/active_record_ext.rb +0 -65
  88. data/lib/passwd/base.rb +0 -31
  89. data/lib/passwd/configuration.rb +0 -82
  90. data/lib/passwd/password.rb +0 -89
  91. data/lib/passwd/policy.rb +0 -28
  92. data/lib/passwd/salt.rb +0 -50
  93. data/spec/passwd/.keep +0 -0
  94. data/spec/passwd/active_record_ext_spec.rb +0 -80
  95. data/spec/passwd/base_spec.rb +0 -60
  96. data/spec/passwd/configuration_spec.rb +0 -50
  97. data/spec/passwd/password_spec.rb +0 -156
  98. data/spec/spec_helper.rb +0 -34
  99. data/spec/support/data_util.rb +0 -11
  100. data/spec/support/paths.rb +0 -2
@@ -0,0 +1,37 @@
1
+ module Passwd::Rails
2
+ module ActiveRecordExt
3
+ def with_authenticate(passwd: nil, user_id: :email, salt: :salt, password: :password)
4
+ passwd ||= Passwd.current
5
+ define_singleton_auth_with_passwd(user_id)
6
+ define_instance_auth_with_passwd(passwd, salt, password)
7
+ define_instance_set_password(passwd, salt, password)
8
+ end
9
+
10
+ private
11
+
12
+ def define_singleton_auth_with_passwd(user_id_col)
13
+ define_singleton_method :authenticate do |user_id, plain|
14
+ user = find_by(user_id_col => user_id)
15
+ return nil unless user
16
+
17
+ user.authenticate(plain) ? user : nil
18
+ end
19
+ end
20
+
21
+ def define_instance_auth_with_passwd(passwd, salt_col, password_col)
22
+ define_method :authenticate do |plain|
23
+ passwd.hashed_password(plain, send(salt_col)) == send(password_col)
24
+ end
25
+ end
26
+
27
+ def define_instance_set_password(passwd, salt_col, password_col)
28
+ define_method :set_password do |plain = nil|
29
+ plain ||= passwd.random
30
+ random_salt = Rails.application.config.passwd.random_salt || proc { SecureRandom.uuid }
31
+ send("#{salt_col}=", random_salt.call(self)) unless send(salt_col)
32
+ send("#{password_col}=", passwd.hashed_password(plain, send(salt_col)))
33
+ plain
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,19 +1,18 @@
1
- module Passwd
1
+ class Passwd
2
2
  class Railtie < ::Rails::Railtie
3
3
  config.passwd = ActiveSupport::OrderedOptions.new
4
4
 
5
5
  initializer "passwd" do
6
- require "passwd/action_controller_ext"
7
- require "passwd/active_record_ext"
6
+ require "passwd/rails/action_controller_ext"
7
+ require "passwd/rails/active_record_ext"
8
8
 
9
9
  ActiveSupport.on_load(:action_controller) do
10
- ::ActionController::Base.send(:include, Passwd::ActionControllerExt)
10
+ ::ActionController::Base.send(:include, ::Passwd::Rails::ActionControllerExt)
11
11
  end
12
12
 
13
13
  ActiveSupport.on_load(:active_record) do
14
- ::ActiveRecord::Base.send(:extend, Passwd::ActiveRecordExt)
14
+ ::ActiveRecord::Base.send(:extend, Passwd::Rails::ActiveRecordExt)
15
15
  end
16
16
  end
17
17
  end
18
18
  end
19
-
@@ -1,4 +1,4 @@
1
- module Passwd
2
- VERSION = "0.2.0"
1
+ class Passwd
2
+ VERSION = "0.3.0".freeze
3
3
  end
4
4
 
@@ -1,29 +1,28 @@
1
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path("../lib", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'passwd/version'
3
+ require "passwd/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "passwd"
7
7
  spec.version = Passwd::VERSION
8
8
  spec.authors = ["i2bskn"]
9
9
  spec.email = ["i2bskn@gmail.com"]
10
- spec.description = %q{The various utilities on password}
11
- spec.summary = %q{Password utility}
10
+
11
+ spec.description = %q{Passwd is provide hashed password creation and authentication.}
12
+ spec.summary = %q{Passwd is provide hashed password creation and authentication.}
12
13
  spec.homepage = "https://github.com/i2bskn/passwd"
13
14
  spec.license = "MIT"
14
15
 
15
- spec.files = `git ls-files`.split($/)
16
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
22
  spec.require_paths = ["lib"]
19
23
 
20
24
  spec.add_development_dependency "bundler"
21
25
  spec.add_development_dependency "rake"
22
- spec.add_development_dependency "coveralls"
23
- spec.add_development_dependency "simplecov"
24
- spec.add_development_dependency "rails"
25
- spec.add_development_dependency "rspec-rails"
26
- spec.add_development_dependency "sqlite3"
27
- spec.add_development_dependency "database_rewinder"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ spec.add_development_dependency "pry"
28
28
  end
29
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: passwd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - i2bskn
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2014-11-23 00:00:00.000000000 Z
11
+ date: 2018-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -39,77 +39,21 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: coveralls
42
+ name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: simplecov
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rails
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec-rails
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: sqlite3
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
45
+ - - "~>"
102
46
  - !ruby/object:Gem::Version
103
- version: '0'
47
+ version: '5.0'
104
48
  type: :development
105
49
  prerelease: false
106
50
  version_requirements: !ruby/object:Gem::Requirement
107
51
  requirements:
108
- - - ">="
52
+ - - "~>"
109
53
  - !ruby/object:Gem::Version
110
- version: '0'
54
+ version: '5.0'
111
55
  - !ruby/object:Gem::Dependency
112
- name: database_rewinder
56
+ name: pry
113
57
  requirement: !ruby/object:Gem::Requirement
114
58
  requirements:
115
59
  - - ">="
@@ -122,102 +66,32 @@ dependencies:
122
66
  - - ">="
123
67
  - !ruby/object:Gem::Version
124
68
  version: '0'
125
- description: The various utilities on password
69
+ description: Passwd is provide hashed password creation and authentication.
126
70
  email:
127
71
  - i2bskn@gmail.com
128
72
  executables: []
129
73
  extensions: []
130
74
  extra_rdoc_files: []
131
75
  files:
132
- - ".coveralls.yml"
133
76
  - ".gitignore"
134
77
  - ".travis.yml"
135
- - CHANGELOG.md
136
78
  - Gemfile
137
- - LICENSE.txt
79
+ - LICENSE
138
80
  - README.md
139
81
  - Rakefile
140
- - example/.gitignore
141
- - example/Gemfile
142
- - example/README.rdoc
143
- - example/Rakefile
144
- - example/app/assets/images/.keep
145
- - example/app/assets/javascripts/application.js
146
- - example/app/assets/stylesheets/application.css
147
- - example/app/controllers/application_controller.rb
148
- - example/app/controllers/concerns/.keep
149
- - example/app/controllers/profiles_controller.rb
150
- - example/app/controllers/root_controller.rb
151
- - example/app/controllers/sessions_controller.rb
152
- - example/app/helpers/application_helper.rb
153
- - example/app/mailers/.keep
154
- - example/app/models/.keep
155
- - example/app/models/concerns/.keep
156
- - example/app/models/user.rb
157
- - example/app/views/layouts/application.html.erb
158
- - example/app/views/profiles/edit.html.erb
159
- - example/app/views/profiles/show.html.erb
160
- - example/app/views/root/index.html.erb
161
- - example/app/views/sessions/new.html.erb
162
- - example/bin/bundle
163
- - example/bin/rails
164
- - example/bin/rake
165
- - example/config.ru
166
- - example/config/application.rb
167
- - example/config/boot.rb
168
- - example/config/database.yml
169
- - example/config/environment.rb
170
- - example/config/environments/development.rb
171
- - example/config/environments/production.rb
172
- - example/config/environments/test.rb
173
- - example/config/initializers/assets.rb
174
- - example/config/initializers/backtrace_silencers.rb
175
- - example/config/initializers/cookies_serializer.rb
176
- - example/config/initializers/filter_parameter_logging.rb
177
- - example/config/initializers/inflections.rb
178
- - example/config/initializers/mime_types.rb
179
- - example/config/initializers/passwd.rb
180
- - example/config/initializers/session_store.rb
181
- - example/config/initializers/wrap_parameters.rb
182
- - example/config/locales/en.yml
183
- - example/config/routes.rb
184
- - example/config/secrets.yml
185
- - example/db/migrate/20141122165914_create_users.rb
186
- - example/db/schema.rb
187
- - example/db/seeds.rb
188
- - example/lib/assets/.keep
189
- - example/lib/tasks/.keep
190
- - example/lib/tasks/user.rake
191
- - example/log/.keep
192
- - example/public/404.html
193
- - example/public/422.html
194
- - example/public/500.html
195
- - example/public/favicon.ico
196
- - example/public/robots.txt
197
- - example/vendor/assets/javascripts/.keep
198
- - example/vendor/assets/stylesheets/.keep
199
- - lib/generators/passwd/config_generator.rb
200
- - lib/generators/passwd/templates/passwd_config.rb
82
+ - bin/console
83
+ - bin/setup
84
+ - lib/generators/passwd/install/USAGE
85
+ - lib/generators/passwd/install/install_generator.rb
86
+ - lib/generators/passwd/install/templates/passwd.rb
201
87
  - lib/passwd.rb
202
- - lib/passwd/action_controller_ext.rb
203
- - lib/passwd/active_record_ext.rb
204
- - lib/passwd/base.rb
205
- - lib/passwd/configuration.rb
88
+ - lib/passwd/config.rb
206
89
  - lib/passwd/errors.rb
207
- - lib/passwd/password.rb
208
- - lib/passwd/policy.rb
90
+ - lib/passwd/rails/action_controller_ext.rb
91
+ - lib/passwd/rails/active_record_ext.rb
209
92
  - lib/passwd/railtie.rb
210
- - lib/passwd/salt.rb
211
93
  - lib/passwd/version.rb
212
94
  - passwd.gemspec
213
- - spec/passwd/.keep
214
- - spec/passwd/active_record_ext_spec.rb
215
- - spec/passwd/base_spec.rb
216
- - spec/passwd/configuration_spec.rb
217
- - spec/passwd/password_spec.rb
218
- - spec/spec_helper.rb
219
- - spec/support/data_util.rb
220
- - spec/support/paths.rb
221
95
  homepage: https://github.com/i2bskn/passwd
222
96
  licenses:
223
97
  - MIT
@@ -238,16 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
112
  version: '0'
239
113
  requirements: []
240
114
  rubyforge_project:
241
- rubygems_version: 2.2.2
115
+ rubygems_version: 2.6.11
242
116
  signing_key:
243
117
  specification_version: 4
244
- summary: Password utility
245
- test_files:
246
- - spec/passwd/.keep
247
- - spec/passwd/active_record_ext_spec.rb
248
- - spec/passwd/base_spec.rb
249
- - spec/passwd/configuration_spec.rb
250
- - spec/passwd/password_spec.rb
251
- - spec/spec_helper.rb
252
- - spec/support/data_util.rb
253
- - spec/support/paths.rb
118
+ summary: Passwd is provide hashed password creation and authentication.
119
+ test_files: []
@@ -1 +0,0 @@
1
- repo_token: 106V5oEIwXeOfqT35UWifTnifi5sEO2QP
@@ -1,35 +0,0 @@
1
- ## 0.2.0
2
-
3
- Remake the this library.
4
-
5
- #### Upgrade
6
-
7
- 1. Run the following commands.
8
-
9
- ```
10
- $ bundle update passwd
11
- $ bundle exec rails gneratate passwd:config
12
- ```
13
-
14
- 2. Migrate your passwd settings to `config/initializers/passwd.rb`.
15
- 3. Updates your code!
16
-
17
- #### Changes
18
-
19
- - Add extention to ActiveController.
20
- - Add `current_user`, `signin!` and `signout!` to ActionController.
21
- - Add `require_signin` method for `before_action`.
22
- - Include the `Passwd::ActiveRecord` was no longer needed.
23
- - Rename method `define_column` to `with_authenticate` in your User model.
24
- - Rename method `Passwd.create` to `Passwd.random`.
25
- - Rename method `Passwd.hashing` to `Passwd.digest`.
26
- - Add `passwd` method User class. Create Passwd::Password object from target user attributes.
27
- - Split object password and salt.
28
-
29
- ## 0.1.5
30
-
31
- #### Changes
32
-
33
- - Can be specified algorithm of hashing
34
- - Change default hashing algorithm to SHA512 from SHA1
35
-
@@ -1,23 +0,0 @@
1
- Copyright (c) 2013-2014 i2bskn
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
-
@@ -1,16 +0,0 @@
1
- # See https://help.github.com/articles/ignoring-files for more about ignoring files.
2
- #
3
- # If you find yourself ignoring temporary files generated by your text editor
4
- # or operating system, you probably want to add a global ignore instead:
5
- # git config --global core.excludesfile '~/.gitignore_global'
6
-
7
- # Ignore bundler config.
8
- /.bundle
9
-
10
- # Ignore the default SQLite database.
11
- /db/*.sqlite3
12
- /db/*.sqlite3-journal
13
-
14
- # Ignore all logfiles and tempfiles.
15
- /log/*.log
16
- /tmp
@@ -1,25 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
-
4
- # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5
- gem 'rails', '4.1.8'
6
- # Use sqlite3 as the database for Active Record
7
- gem 'sqlite3'
8
- # Use SCSS for stylesheets
9
- gem 'sass-rails', '~> 4.0.3'
10
- # Use Uglifier as compressor for JavaScript assets
11
- gem 'uglifier', '>= 1.3.0'
12
- # Use CoffeeScript for .js.coffee assets and views
13
- gem 'coffee-rails', '~> 4.0.0'
14
-
15
- # Use jquery as the JavaScript library
16
- gem 'jquery-rails'
17
- # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
18
- gem 'jbuilder', '~> 2.0'
19
-
20
- gem 'passwd', path: File.expand_path("../..", __FILE__)
21
-
22
- group :development do
23
- gem 'pry-rails'
24
- end
25
-