Skip to content

Commit 69a55c2

Browse files
authored
Fix valid_password? not using configured values when called alone (#293)
* Fix valid_password? not using configured values when called alone * Make set_encryption_attributes a public method (will be removed in v1) * Remove unused instance method * Update changelog
1 parent 24efa86 commit 69a55c2

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Inline core migration index definition [#281](https://github.com/Sorcery/sorcery/pull/281)
55
* Fix MongoID adapter breaking on save [#284](https://github.com/Sorcery/sorcery/pull/284)
66
* Don't pass token to Slack in query params. Prevents 'invalid_auth' error [#287](https://github.com/Sorcery/sorcery/pull/287)
7+
* Fix valid_password? not using configured values when called alone [#293](https://github.com/Sorcery/sorcery/pull/293)
78

89
## 0.16.1
910

lib/sorcery/model.rb

+11-6
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ def encrypt(*tokens)
131131
@sorcery_config.encryption_provider.encrypt(*tokens)
132132
end
133133

134+
# FIXME: This method of passing config to the hashing provider is
135+
# questionable, and has been refactored in Sorcery v1.
136+
def set_encryption_attributes
137+
@sorcery_config.encryption_provider.stretches = @sorcery_config.stretches if @sorcery_config.encryption_provider.respond_to?(:stretches) && @sorcery_config.stretches
138+
@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
139+
@sorcery_config.encryption_provider.pepper = @sorcery_config.pepper if @sorcery_config.encryption_provider.respond_to?(:pepper) && @sorcery_config.pepper
140+
end
141+
134142
protected
135143

136144
def authentication_response(options = {})
@@ -139,12 +147,6 @@ def authentication_response(options = {})
139147
options[:return_value]
140148
end
141149

142-
def set_encryption_attributes
143-
@sorcery_config.encryption_provider.stretches = @sorcery_config.stretches if @sorcery_config.encryption_provider.respond_to?(:stretches) && @sorcery_config.stretches
144-
@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
145-
@sorcery_config.encryption_provider.pepper = @sorcery_config.pepper if @sorcery_config.encryption_provider.respond_to?(:pepper) && @sorcery_config.pepper
146-
end
147-
148150
def add_config_inheritance
149151
class_eval do
150152
def self.inherited(subclass)
@@ -177,6 +179,9 @@ def valid_password?(pass)
177179
crypted = send(sorcery_config.crypted_password_attribute_name)
178180
return crypted == pass if sorcery_config.encryption_provider.nil?
179181

182+
# Ensure encryption provider is using configured values
183+
self.class.set_encryption_attributes
184+
180185
salt = send(sorcery_config.salt_attribute_name) unless sorcery_config.salt_attribute_name.nil?
181186

182187
sorcery_config.encryption_provider.matches?(crypted, pass, salt)

0 commit comments

Comments
 (0)