Skip to content

Fix valid_password? not using configured values when called alone #293

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

Merged
merged 4 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Inline core migration index definition [#281](https://github.com/Sorcery/sorcery/pull/281)
* Fix MongoID adapter breaking on save [#284](https://github.com/Sorcery/sorcery/pull/284)
* Don't pass token to Slack in query params. Prevents 'invalid_auth' error [#287](https://github.com/Sorcery/sorcery/pull/287)
* Fix valid_password? not using configured values when called alone [#293](https://github.com/Sorcery/sorcery/pull/293)

## 0.16.1

Expand Down
17 changes: 11 additions & 6 deletions lib/sorcery/model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ def encrypt(*tokens)
@sorcery_config.encryption_provider.encrypt(*tokens)
end

# FIXME: This method of passing config to the hashing provider is
# questionable, and has been refactored in Sorcery v1.
def set_encryption_attributes
@sorcery_config.encryption_provider.stretches = @sorcery_config.stretches if @sorcery_config.encryption_provider.respond_to?(:stretches) && @sorcery_config.stretches
@sorcery_config.encryption_provider.join_token = @sorcery_config.salt_join_token if @sorcery_config.encryption_provider.respond_to?(:join_token) && @sorcery_config.salt_join_token
@sorcery_config.encryption_provider.pepper = @sorcery_config.pepper if @sorcery_config.encryption_provider.respond_to?(:pepper) && @sorcery_config.pepper
end

protected

def authentication_response(options = {})
Expand All @@ -139,12 +147,6 @@ def authentication_response(options = {})
options[:return_value]
end

def set_encryption_attributes
@sorcery_config.encryption_provider.stretches = @sorcery_config.stretches if @sorcery_config.encryption_provider.respond_to?(:stretches) && @sorcery_config.stretches
@sorcery_config.encryption_provider.join_token = @sorcery_config.salt_join_token if @sorcery_config.encryption_provider.respond_to?(:join_token) && @sorcery_config.salt_join_token
@sorcery_config.encryption_provider.pepper = @sorcery_config.pepper if @sorcery_config.encryption_provider.respond_to?(:pepper) && @sorcery_config.pepper
end

def add_config_inheritance
class_eval do
def self.inherited(subclass)
Expand Down Expand Up @@ -177,6 +179,9 @@ def valid_password?(pass)
crypted = send(sorcery_config.crypted_password_attribute_name)
return crypted == pass if sorcery_config.encryption_provider.nil?

# Ensure encryption provider is using configured values
self.class.set_encryption_attributes

salt = send(sorcery_config.salt_attribute_name) unless sorcery_config.salt_attribute_name.nil?

sorcery_config.encryption_provider.matches?(crypted, pass, salt)
Expand Down