-
Notifications
You must be signed in to change notification settings - Fork 167
Replace bcrypt with pbkdf2 password hashing #519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d5ab0f2
Replace bcrypt with pbkdf2 hashing
e420bdd
bump up pbkdf2 iterations to ~0.5sec
3616e47
pbkdf2 iterations at 100_000
8067934
must set stretches > 1000 or it will be overridden in the devise plugin
5731222
recovery code feature was assuming Devise was using bcrypt encryption…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ class User < ActiveRecord::Base | |
|
|
||
| after_validation :set_default_role, if: :new_record? | ||
|
|
||
| devise :confirmable, :database_authenticatable, :recoverable, :registerable, | ||
| devise :confirmable, :database_authenticatable, :encryptable, :recoverable, :registerable, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as other PR -- thoughts on listing each item on its own line? |
||
| :timeoutable, :trackable, :two_factor_authenticatable, :omniauthable, | ||
| omniauth_providers: [:saml] | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,13 @@ | ||
| class RecoveryCodeGenerator | ||
| STRETCHES = 12 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what does this mean? |
||
|
|
||
| def self.compare(hashed_code, recovery_code) | ||
| return false if hashed_code.blank? | ||
| bcrypt = BCrypt::Password.new(hashed_code) | ||
| password = BCrypt::Engine.hash_secret(recovery_code, bcrypt.salt) | ||
| Devise.secure_compare(password, hashed_code) | ||
| end | ||
|
|
||
| def initialize(user, length: 16) | ||
| @user = user | ||
| @length = length | ||
|
|
@@ -15,7 +24,7 @@ def create | |
| attr_reader :length, :user | ||
|
|
||
| def hashed_code | ||
| Devise::Encryptor.digest(User, raw_recovery_code) | ||
| BCrypt::Password.create(raw_recovery_code, cost: STRETCHES).to_s | ||
| end | ||
|
|
||
| def raw_recovery_code | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| class AddUsersSalt < ActiveRecord::Migration | ||
| def change | ||
| add_column :users, :password_salt, :string | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was going to ask if this is something we can PR back to the main lib, but I see you already did that! heartcombo/devise-encryptable#12
Maybe add Pr link to Gemfile in case we forget to switch this out when it is merged?