devise-security 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +38 -0
  4. data/.rubocop.yml +42 -0
  5. data/.travis.yml +14 -0
  6. data/Gemfile +2 -0
  7. data/Gemfile.lock +199 -0
  8. data/LICENSE.txt +20 -0
  9. data/README.md +263 -0
  10. data/Rakefile +26 -0
  11. data/app/controllers/devise/paranoid_verification_code_controller.rb +42 -0
  12. data/app/controllers/devise/password_expired_controller.rb +48 -0
  13. data/app/views/devise/paranoid_verification_code/show.html.erb +10 -0
  14. data/app/views/devise/password_expired/show.html.erb +16 -0
  15. data/config/locales/de.yml +16 -0
  16. data/config/locales/en.yml +17 -0
  17. data/config/locales/es.yml +17 -0
  18. data/config/locales/it.yml +10 -0
  19. data/devise-security.gemspec +34 -0
  20. data/lib/devise-security.rb +106 -0
  21. data/lib/devise-security/controllers/helpers.rb +96 -0
  22. data/lib/devise-security/hooks/expirable.rb +10 -0
  23. data/lib/devise-security/hooks/paranoid_verification.rb +5 -0
  24. data/lib/devise-security/hooks/password_expirable.rb +5 -0
  25. data/lib/devise-security/hooks/session_limitable.rb +27 -0
  26. data/lib/devise-security/models/database_authenticatable_patch.rb +26 -0
  27. data/lib/devise-security/models/expirable.rb +120 -0
  28. data/lib/devise-security/models/old_password.rb +4 -0
  29. data/lib/devise-security/models/paranoid_verification.rb +35 -0
  30. data/lib/devise-security/models/password_archivable.rb +80 -0
  31. data/lib/devise-security/models/password_expirable.rb +67 -0
  32. data/lib/devise-security/models/secure_validatable.rb +100 -0
  33. data/lib/devise-security/models/security_questionable.rb +18 -0
  34. data/lib/devise-security/models/session_limitable.rb +21 -0
  35. data/lib/devise-security/orm/active_record.rb +20 -0
  36. data/lib/devise-security/patches.rb +21 -0
  37. data/lib/devise-security/patches/confirmations_controller_captcha.rb +21 -0
  38. data/lib/devise-security/patches/confirmations_controller_security_question.rb +25 -0
  39. data/lib/devise-security/patches/controller_captcha.rb +17 -0
  40. data/lib/devise-security/patches/controller_security_question.rb +20 -0
  41. data/lib/devise-security/patches/passwords_controller_captcha.rb +20 -0
  42. data/lib/devise-security/patches/passwords_controller_security_question.rb +24 -0
  43. data/lib/devise-security/patches/registrations_controller_captcha.rb +33 -0
  44. data/lib/devise-security/patches/sessions_controller_captcha.rb +24 -0
  45. data/lib/devise-security/patches/unlocks_controller_captcha.rb +20 -0
  46. data/lib/devise-security/patches/unlocks_controller_security_question.rb +24 -0
  47. data/lib/devise-security/rails.rb +17 -0
  48. data/lib/devise-security/routes.rb +17 -0
  49. data/lib/devise-security/schema.rb +59 -0
  50. data/lib/devise-security/version.rb +3 -0
  51. data/lib/generators/devise-security/install_generator.rb +26 -0
  52. data/lib/generators/templates/devise-security.rb +38 -0
  53. data/test/dummy/Rakefile +6 -0
  54. data/test/dummy/app/controllers/application_controller.rb +2 -0
  55. data/test/dummy/app/controllers/captcha/sessions_controller.rb +3 -0
  56. data/test/dummy/app/controllers/foos_controller.rb +0 -0
  57. data/test/dummy/app/controllers/security_question/unlocks_controller.rb +3 -0
  58. data/test/dummy/app/models/.gitkeep +0 -0
  59. data/test/dummy/app/models/captcha_user.rb +5 -0
  60. data/test/dummy/app/models/secure_user.rb +3 -0
  61. data/test/dummy/app/models/security_question_user.rb +6 -0
  62. data/test/dummy/app/models/user.rb +5 -0
  63. data/test/dummy/app/views/foos/index.html.erb +0 -0
  64. data/test/dummy/config.ru +4 -0
  65. data/test/dummy/config/application.rb +24 -0
  66. data/test/dummy/config/boot.rb +6 -0
  67. data/test/dummy/config/database.yml +7 -0
  68. data/test/dummy/config/environment.rb +5 -0
  69. data/test/dummy/config/environments/test.rb +27 -0
  70. data/test/dummy/config/initializers/devise.rb +9 -0
  71. data/test/dummy/config/initializers/migration_class.rb +6 -0
  72. data/test/dummy/config/routes.rb +10 -0
  73. data/test/dummy/config/secrets.yml +3 -0
  74. data/test/dummy/db/migrate/20120508165529_create_tables.rb +33 -0
  75. data/test/dummy/db/migrate/20150402165590_add_verification_columns.rb +11 -0
  76. data/test/dummy/db/migrate/20150407162345_add_verification_attempt_column.rb +9 -0
  77. data/test/dummy/db/migrate/20160320162345_add_security_questions_fields.rb +8 -0
  78. data/test/test_captcha_controller.rb +58 -0
  79. data/test/test_helper.rb +13 -0
  80. data/test/test_install_generator.rb +16 -0
  81. data/test/test_paranoid_verification.rb +124 -0
  82. data/test/test_password_archivable.rb +61 -0
  83. data/test/test_password_expirable.rb +32 -0
  84. data/test/test_password_expired_controller.rb +29 -0
  85. data/test/test_secure_validatable.rb +85 -0
  86. data/test/test_security_question_controller.rb +60 -0
  87. metadata +315 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b562461dba8b930f89dd68682f11d354a83f7a28
4
+ data.tar.gz: ffbac7216ea17728e7d483e846e63bfe773bbd8a
5
+ SHA512:
6
+ metadata.gz: 6031c3ac9f30e9d09501d90d2f263a2600f4919dd79f0b99275b2be4a93732b8a5eddbadf6c95e6a9ba117932cfaba5357cdeb0036b34b2810909f2536eb269b
7
+ data.tar.gz: cd0a3386d268be89049f2fef0edf39b768d2b31b81335e79771d22b56c3575e34f23444b51a42006e0540b272df0602c323d35e60e31d06f1d916902633ae0a1
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,38 @@
1
+ test/rails_app/log/*
2
+ test/rails_app/tmp/*
3
+ *~
4
+ coverage/*
5
+ *.sqlite3
6
+ .bundle
7
+ rdoc/*
8
+ pkg
9
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
10
+ #
11
+ # * Create a file at ~/.gitignore
12
+ # * Include files you want ignored
13
+ # * Run: git config --global core.excludesfile ~/.gitignore
14
+ #
15
+ # After doing this, these files will be ignored in all your git projects,
16
+ # saving you from having to 'pollute' every project you touch with them
17
+ #
18
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
19
+ #
20
+ # For MacOS:
21
+ #
22
+ #.DS_Store
23
+ #
24
+ # For TextMate
25
+ #*.tmproj
26
+ #tmtags
27
+ #
28
+ # For emacs:
29
+ #*~
30
+ #\#*
31
+ #.\#*
32
+ #
33
+ # For vim:
34
+ #*.swp
35
+
36
+ log
37
+ test/tmp/*
38
+ *.gem
@@ -0,0 +1,42 @@
1
+ AllCops:
2
+ Include:
3
+ - '**/Rakefile'
4
+ - '**/config.ru'
5
+ - 'lib/tasks/**/*'
6
+ Exclude:
7
+ - Gemfile*
8
+ - 'db/**/*'
9
+ - 'config/**/*'
10
+ - 'bin/**/*'
11
+ - 'vendor/bundle/**/*'
12
+ - 'spec/support/**/*' # rspec support helpers have a strange api
13
+
14
+ Rails:
15
+ Enabled: true
16
+
17
+ # We don't care about method length, since we check method cyclomatic
18
+ # complexity.
19
+ Metrics/MethodLength:
20
+ Enabled: false
21
+
22
+ # Trailing commas make for clearer diffs because the last line won't appear
23
+ # to have been changed, as it would if it lacked a comma and had one added.
24
+ Style/TrailingCommaInLiteral:
25
+ EnforcedStyleForMultiline: comma
26
+ Style/TrailingCommaInArguments:
27
+ EnforcedStyleForMultiline: comma
28
+
29
+ # Cop supports --auto-correct.
30
+ # Configuration parameters: PreferredDelimiters.
31
+ Style/PercentLiteralDelimiters:
32
+ PreferredDelimiters:
33
+ # Using `[]` for string arrays instead of `()`, since normal arrays are
34
+ # indicated with `[]` not `()`.
35
+ '%w': '[]'
36
+ '%W': '[]'
37
+
38
+ Style/AndOr:
39
+ # Whether `and` and `or` are banned only in conditionals (conditionals)
40
+ # or completely (always).
41
+ # They read better, more like normal English.
42
+ Enabled: false
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ before_install: gem install bundler && bundler -v
3
+ install: bundle install --jobs=3 --retry=3
4
+ before_script: bundle install
5
+ script: bundle exec rake
6
+ rvm:
7
+ - 2.1.8
8
+ - 2.2.4
9
+ - 2.3.4
10
+ - 2.4.1
11
+ - ruby-head
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
@@ -0,0 +1,199 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ devise-security (0.11.0)
5
+ devise (>= 3.0.0, < 5.0)
6
+ railties (>= 3.2.6, < 6.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actioncable (5.1.3)
12
+ actionpack (= 5.1.3)
13
+ nio4r (~> 2.0)
14
+ websocket-driver (~> 0.6.1)
15
+ actionmailer (5.1.3)
16
+ actionpack (= 5.1.3)
17
+ actionview (= 5.1.3)
18
+ activejob (= 5.1.3)
19
+ mail (~> 2.5, >= 2.5.4)
20
+ rails-dom-testing (~> 2.0)
21
+ actionpack (5.1.3)
22
+ actionview (= 5.1.3)
23
+ activesupport (= 5.1.3)
24
+ rack (~> 2.0)
25
+ rack-test (~> 0.6.3)
26
+ rails-dom-testing (~> 2.0)
27
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
+ actionview (5.1.3)
29
+ activesupport (= 5.1.3)
30
+ builder (~> 3.1)
31
+ erubi (~> 1.4)
32
+ rails-dom-testing (~> 2.0)
33
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
+ activejob (5.1.3)
35
+ activesupport (= 5.1.3)
36
+ globalid (>= 0.3.6)
37
+ activemodel (5.1.3)
38
+ activesupport (= 5.1.3)
39
+ activerecord (5.1.3)
40
+ activemodel (= 5.1.3)
41
+ activesupport (= 5.1.3)
42
+ arel (~> 8.0)
43
+ activesupport (5.1.3)
44
+ concurrent-ruby (~> 1.0, >= 1.0.2)
45
+ i18n (~> 0.7)
46
+ minitest (~> 5.1)
47
+ tzinfo (~> 1.1)
48
+ arel (8.0.0)
49
+ ast (2.3.0)
50
+ bcrypt (3.1.11)
51
+ builder (3.2.3)
52
+ concurrent-ruby (1.0.5)
53
+ coveralls (0.8.21)
54
+ json (>= 1.8, < 3)
55
+ simplecov (~> 0.14.1)
56
+ term-ansicolor (~> 1.3)
57
+ thor (~> 0.19.4)
58
+ tins (~> 1.6)
59
+ devise (4.3.0)
60
+ bcrypt (~> 3.0)
61
+ orm_adapter (~> 0.1)
62
+ railties (>= 4.1.0, < 5.2)
63
+ responders
64
+ warden (~> 1.2.3)
65
+ diff-lcs (1.3)
66
+ docile (1.1.5)
67
+ easy_captcha (0.6.5)
68
+ bundler (>= 1.1.0)
69
+ rails (>= 3.0.0)
70
+ rmagick (>= 2.13.1)
71
+ rspec-rails (>= 2.8.1)
72
+ simplecov (>= 0.3.8)
73
+ yard (>= 0.7.0)
74
+ erubi (1.6.1)
75
+ globalid (0.4.0)
76
+ activesupport (>= 4.2.0)
77
+ i18n (0.8.6)
78
+ json (2.1.0)
79
+ loofah (2.0.3)
80
+ nokogiri (>= 1.5.9)
81
+ mail (2.6.6)
82
+ mime-types (>= 1.16, < 4)
83
+ method_source (0.8.2)
84
+ mime-types (3.1)
85
+ mime-types-data (~> 3.2015)
86
+ mime-types-data (3.2016.0521)
87
+ mini_portile2 (2.2.0)
88
+ minitest (5.10.3)
89
+ nio4r (2.1.0)
90
+ nokogiri (1.8.0)
91
+ mini_portile2 (~> 2.2.0)
92
+ orm_adapter (0.5.0)
93
+ parallel (1.12.0)
94
+ parser (2.4.0.0)
95
+ ast (~> 2.2)
96
+ powerpack (0.1.1)
97
+ rack (2.0.3)
98
+ rack-test (0.6.3)
99
+ rack (>= 1.0)
100
+ rails (5.1.3)
101
+ actioncable (= 5.1.3)
102
+ actionmailer (= 5.1.3)
103
+ actionpack (= 5.1.3)
104
+ actionview (= 5.1.3)
105
+ activejob (= 5.1.3)
106
+ activemodel (= 5.1.3)
107
+ activerecord (= 5.1.3)
108
+ activesupport (= 5.1.3)
109
+ bundler (>= 1.3.0)
110
+ railties (= 5.1.3)
111
+ sprockets-rails (>= 2.0.0)
112
+ rails-dom-testing (2.0.3)
113
+ activesupport (>= 4.2.0)
114
+ nokogiri (>= 1.6)
115
+ rails-html-sanitizer (1.0.3)
116
+ loofah (~> 2.0)
117
+ rails_email_validator (0.1.4)
118
+ activemodel (>= 3.0.0)
119
+ railties (5.1.3)
120
+ actionpack (= 5.1.3)
121
+ activesupport (= 5.1.3)
122
+ method_source
123
+ rake (>= 0.8.7)
124
+ thor (>= 0.18.1, < 2.0)
125
+ rainbow (2.2.2)
126
+ rake
127
+ rake (12.0.0)
128
+ responders (2.4.0)
129
+ actionpack (>= 4.2.0, < 5.3)
130
+ railties (>= 4.2.0, < 5.3)
131
+ rmagick (2.16.0)
132
+ rspec-core (3.6.0)
133
+ rspec-support (~> 3.6.0)
134
+ rspec-expectations (3.6.0)
135
+ diff-lcs (>= 1.2.0, < 2.0)
136
+ rspec-support (~> 3.6.0)
137
+ rspec-mocks (3.6.0)
138
+ diff-lcs (>= 1.2.0, < 2.0)
139
+ rspec-support (~> 3.6.0)
140
+ rspec-rails (3.6.1)
141
+ actionpack (>= 3.0)
142
+ activesupport (>= 3.0)
143
+ railties (>= 3.0)
144
+ rspec-core (~> 3.6.0)
145
+ rspec-expectations (~> 3.6.0)
146
+ rspec-mocks (~> 3.6.0)
147
+ rspec-support (~> 3.6.0)
148
+ rspec-support (3.6.0)
149
+ rubocop (0.49.1)
150
+ parallel (~> 1.10)
151
+ parser (>= 2.3.3.1, < 3.0)
152
+ powerpack (~> 0.1)
153
+ rainbow (>= 1.99.1, < 3.0)
154
+ ruby-progressbar (~> 1.7)
155
+ unicode-display_width (~> 1.0, >= 1.0.1)
156
+ ruby-progressbar (1.8.1)
157
+ simplecov (0.14.1)
158
+ docile (~> 1.1.0)
159
+ json (>= 1.8, < 3)
160
+ simplecov-html (~> 0.10.0)
161
+ simplecov-html (0.10.2)
162
+ sprockets (3.7.1)
163
+ concurrent-ruby (~> 1.0)
164
+ rack (> 1, < 3)
165
+ sprockets-rails (3.2.0)
166
+ actionpack (>= 4.0)
167
+ activesupport (>= 4.0)
168
+ sprockets (>= 3.0.0)
169
+ sqlite3 (1.3.13)
170
+ term-ansicolor (1.6.0)
171
+ tins (~> 1.0)
172
+ thor (0.19.4)
173
+ thread_safe (0.3.6)
174
+ tins (1.15.0)
175
+ tzinfo (1.2.3)
176
+ thread_safe (~> 0.1)
177
+ unicode-display_width (1.3.0)
178
+ warden (1.2.7)
179
+ rack (>= 1.0)
180
+ websocket-driver (0.6.5)
181
+ websocket-extensions (>= 0.1.0)
182
+ websocket-extensions (0.1.2)
183
+ yard (0.9.9)
184
+
185
+ PLATFORMS
186
+ ruby
187
+
188
+ DEPENDENCIES
189
+ bundler (>= 1.3.0, < 2.0)
190
+ coveralls (~> 0.8)
191
+ devise-security!
192
+ easy_captcha (~> 0)
193
+ minitest (~> 5.0)
194
+ rails_email_validator (~> 0)
195
+ rubocop (~> 0)
196
+ sqlite3 (~> 1.3, >= 1.3.10)
197
+
198
+ BUNDLED WITH
199
+ 1.15.3
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Marco Scholl
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,263 @@
1
+ # Devise Security
2
+
3
+ [![Build Status](https://travis-ci.org/devise-security/devise-security.svg?branch=master)](https://travis-ci.org/devise-security/devise-security)
4
+
5
+ A [Devise](https://github.com/plataformatec/devise) extension to add additional security features required by modern web applications. Forked from [Devise Security Extension](https://github.com/phatworx/devise_security_extension)
6
+
7
+ It is composed of 7 additional Devise modules:
8
+
9
+ * `:password_expirable` - passwords will expire after a configured time (and will need an update). You will most likely want to use `:password_expirable` together with the `:password_archivable` module to [prevent the current expired password being reused](https://github.com/phatworx/devise-security/issues/175) immediately as the new password.
10
+ * `:secure_validatable` - better way to validate a model (email, stronger password validation). Don't use with Devise `:validatable` module!
11
+ * `:password_archivable` - save used passwords in an `old_passwords` table for history checks (don't be able to use a formerly used password)
12
+ * `:session_limitable` - ensures, that there is only one session usable per account at once
13
+ * `:expirable` - expires a user account after x days of inactivity (default 90 days)
14
+ * `:security_questionable` - as accessible substitution for captchas (security question with captcha fallback)
15
+ * `:paranoid_verification` - admin can generate verification code that user needs to fill in otherwise he wont be able to use the application.
16
+
17
+ Configuration and database schema for each module below.
18
+
19
+ ## Additional features
20
+
21
+ * **captcha support** for `sign_up`, `sign_in`, `recover` and `unlock` (to make automated mass creation and brute forcing of accounts harder)
22
+
23
+ ## Getting started
24
+
25
+ Devise Security Extension works with Devise on Rails 3.2 onwards. You can add it to your Gemfile after you successfully set up Devise (see [Devise documentation](https://github.com/plataformatec/devise)) with:
26
+
27
+ ```ruby
28
+ gem 'devise-security'
29
+ ```
30
+
31
+ Run the bundle command to install it.
32
+
33
+ After you installed Devise Security Extension you need to run the generator:
34
+
35
+ ```console
36
+ rails generate devise-security:install
37
+ ```
38
+
39
+ The generator adds optional configurations to `config/initializers/devise.rb`. Enable
40
+ the modules you wish to use in the initializer you are ready to add Devise Security Extension modules on top of Devise modules to any of your Devise models:
41
+
42
+ ```ruby
43
+ devise :password_expirable, :secure_validatable, :password_archivable, :session_limitable, :expirable
44
+ ```
45
+
46
+ for `:secure_validatable` you need to add
47
+
48
+ ```ruby
49
+ gem 'rails_email_validator'
50
+ ```
51
+
52
+ ## Configuration
53
+
54
+ ```ruby
55
+ Devise.setup do |config|
56
+ # ==> Security Extension
57
+ # Configure security extension for devise
58
+
59
+ # Should the password expire (e.g 3.months)
60
+ # config.expire_password_after = 3.months
61
+
62
+ # Need 1 char of A-Z, a-z and 0-9
63
+ # config.password_regex = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/
64
+
65
+ # Number of old passwords in archive
66
+ # config.password_archiving_count = 5
67
+
68
+ # Deny old password (true, false, count)
69
+ # config.deny_old_passwords = true
70
+
71
+ # captcha integration for recover form
72
+ # config.captcha_for_recover = true
73
+
74
+ # captcha integration for sign up form
75
+ # config.captcha_for_sign_up = true
76
+
77
+ # captcha integration for sign in form
78
+ # config.captcha_for_sign_in = true
79
+
80
+ # captcha integration for unlock form
81
+ # config.captcha_for_unlock = true
82
+
83
+ # security_question integration for recover form
84
+ # this automatically enables captchas (captcha_for_recover, as fallback)
85
+ # config.security_question_for_recover = false
86
+
87
+ # security_question integration for unlock form
88
+ # this automatically enables captchas (captcha_for_unlock, as fallback)
89
+ # config.security_question_for_unlock = false
90
+
91
+ # security_question integration for confirmation form
92
+ # this automatically enables captchas (captcha_for_confirmation, as fallback)
93
+ # config.security_question_for_confirmation = false
94
+
95
+ # ==> Configuration for :expirable
96
+ # Time period for account expiry from last_activity_at
97
+ # config.expire_after = 90.days
98
+ end
99
+ ```
100
+
101
+ ## Captcha-Support
102
+ The captcha support depends on [EasyCaptcha](https://github.com/phatworx/easy_captcha). See further documentation there.
103
+
104
+ ### Installation
105
+
106
+ 1. Add EasyCaptcha to your `Gemfile` with
107
+ ```ruby
108
+ gem 'easy_captcha'
109
+ ```
110
+ 2. Run the initializer
111
+ ```ruby
112
+ rails generate easy_captcha:install
113
+ ```
114
+ 3. Enable captcha - see "Configuration" of Devise Security Extension above.
115
+ 4. Add the captcha in the generated devise views for each controller you have activated
116
+ ```erb
117
+ <p><%= captcha_tag %></p>
118
+ <p><%= text_field_tag :captcha %></p>
119
+ ```
120
+
121
+ ## Schema
122
+
123
+ ### Password expirable
124
+ ```ruby
125
+ create_table :the_resources do |t|
126
+ # other devise fields
127
+
128
+ t.datetime :password_changed_at
129
+ end
130
+ add_index :the_resources, :password_changed_at
131
+ ```
132
+
133
+ ### Password archivable
134
+ ```ruby
135
+ create_table :old_passwords do |t|
136
+ t.string :encrypted_password, :null => false
137
+ t.string :password_archivable_type, :null => false
138
+ t.integer :password_archivable_id, :null => false
139
+ t.datetime :created_at
140
+ end
141
+ add_index :old_passwords, [:password_archivable_type, :password_archivable_id], :name => :index_password_archivable
142
+ ```
143
+
144
+ ### Session limitable
145
+ ```ruby
146
+ create_table :the_resources do |t|
147
+ # other devise fields
148
+
149
+ t.string :unique_session_id, :limit => 20
150
+ end
151
+ ```
152
+
153
+ ### Expirable
154
+ ```ruby
155
+ create_table :the_resources do |t|
156
+ # other devise fields
157
+
158
+ t.datetime :last_activity_at
159
+ t.datetime :expired_at
160
+ end
161
+ add_index :the_resources, :last_activity_at
162
+ add_index :the_resources, :expired_at
163
+ ```
164
+
165
+ ### Paranoid verifiable
166
+ ```ruby
167
+ create_table :the_resources do |t|
168
+ # other devise fields
169
+
170
+ t.string :paranoid_verification_code
171
+ t.integer :paranoid_verification_attempt, default: 0
172
+ t.datetime :paranoid_verified_at
173
+ end
174
+ add_index :the_resources, :paranoid_verification_code
175
+ add_index :the_resources, :paranoid_verified_at
176
+ ```
177
+
178
+ [Documentation for Paranoid Verifiable module]( https://github.com/devise-security/devise-security/wiki/Paranoid-Verification)
179
+
180
+ ### Security questionable
181
+
182
+ ```ruby
183
+ # app/models/security_question.rb
184
+ class SecurityQuestion < ActiveRecord::Base
185
+ validates :locale, presence: true
186
+ validates :name, presence: true, uniqueness: true
187
+ end
188
+ ```
189
+
190
+ ```ruby
191
+ create_table :security_questions do |t|
192
+ t.string :locale, :null => false
193
+ t.string :name, :null => false
194
+ end
195
+
196
+ SecurityQuestion.create! locale: :de, name: 'Wie lautet der Geburstname Ihrer Mutter?'
197
+ SecurityQuestion.create! locale: :de, name: 'Wo sind sie geboren?'
198
+ SecurityQuestion.create! locale: :de, name: 'Wie lautet der Name Ihres ersten Haustieres?'
199
+ SecurityQuestion.create! locale: :de, name: 'Was ist Ihr Lieblingsfilm?'
200
+ SecurityQuestion.create! locale: :de, name: 'Was ist Ihr Lieblingsbuch?'
201
+ SecurityQuestion.create! locale: :de, name: 'Was ist Ihr Lieblingstier?'
202
+ SecurityQuestion.create! locale: :de, name: 'Was ist Ihr Lieblings-Reiseland?'
203
+ ```
204
+
205
+
206
+ ```ruby
207
+ add_column :the_resources, :security_question_id, :integer
208
+ add_column :the_resources, :security_question_answer, :string
209
+ ```
210
+
211
+ or
212
+
213
+ ```ruby
214
+ create_table :the_resources do |t|
215
+ # other devise fields
216
+
217
+ t.integer :security_question_id
218
+ t.string :security_question_answer
219
+ end
220
+ ```
221
+
222
+ ## Requirements
223
+
224
+ * Devise (https://github.com/plataformatec/devise)
225
+ * Rails 3.2 onwards (http://github.com/rails/rails)
226
+ * recommendations:
227
+ * `autocomplete-off` (http://github.com/phatworx/autocomplete-off)
228
+ * `easy_captcha` (http://github.com/phatworx/easy_captcha)
229
+ * `rails_email_validator` (http://github.com/phatworx/rails_email_validator)
230
+
231
+
232
+ ## Todo
233
+
234
+ * see the github issues (feature requests)
235
+
236
+ ## History
237
+ * 0.1 expire passwords
238
+ * 0.2 strong password validation
239
+ * 0.3 password archivable with validation
240
+ * 0.4 captcha support for sign_up, sign_in, recover and unlock
241
+ * 0.5 session_limitable module
242
+ * 0.6 expirable module
243
+ * 0.7 security questionable module for recover and unlock
244
+ * 0.8 Support for Rails 4 (+ variety of patches)
245
+ * 0.11 Support for Rails 5. Forked to allow project maintenance and features
246
+
247
+ ## Maintainers
248
+
249
+ * Nate Bird (https://github.com/natebird)
250
+
251
+ ## Contributing to devise-security
252
+
253
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
254
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
255
+ * Fork the project
256
+ * Start a feature/bugfix branch
257
+ * Commit and push until you are happy with your contribution
258
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
259
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
260
+
261
+ ## Copyright
262
+
263
+ Copyright (c) 2011-2017 Marco Scholl. See LICENSE.txt for further details.