Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

:transition_from_crypto_provider now accepts an array

  • Loading branch information...
commit ca2b97276f3baaffac4637065595716499e25a6f 1 parent ae44442
@binarylogic binarylogic authored
View
6 CHANGELOG.rdoc
@@ -1,4 +1,8 @@
-== 1.3.4 released 2008-11-23
+== 1.3.5 released 2008-11-24
+
+* :transition_from_crypto_provider now accepts an array to transition from multiple providers. Which solves the problem of a double transition.
+
+== 1.3.4 released 2008-11-24
* Delegate human_attribute_name to the ActiveRecord class to take advantage of the I18n feature.
* Fixed issue with passwords from older versions of restful_authentication, the passwords end with --
View
2  lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/config.rb
@@ -207,6 +207,8 @@ def acts_as_authentic_with_config(options = {})
options[crypto_provider_key].stretches = 1
end
end
+
+ options[:transition_from_crypto_provider] = [options[:transition_from_crypto_provider]].compact unless options[:transition_from_crypto_provider].is_a?(Array)
class_eval <<-"end_eval", __FILE__, __LINE__
def self.acts_as_authentic_config
View
15 lib/authlogic/orm_adapters/active_record_adapter/acts_as_authentic/credentials.rb
@@ -73,22 +73,17 @@ def #{options[:password_field]}=(pass)
def valid_#{options[:password_field]}?(attempted_password)
return false if attempted_password.blank? || #{options[:crypted_password_field]}.blank? || #{options[:password_salt_field]}.blank?
- [#{options[:crypto_provider]}, #{options[:transition_from_crypto_provider].inspect}].compact.each do |encryptor|
+ ([#{options[:crypto_provider]}] + #{options[:transition_from_crypto_provider].inspect}).each_with_index do |encryptor, index|
# The arguments_type of for the transitioning from restful_authentication
- arguments_type = nil
-
- case encryptor.name
- when "#{options[:crypto_provider]}"
- arguments_type = :restful_authentication if #{options[:act_like_restful_authentication].inspect}
- when "#{options[:transition_from_crypto_provider].inspect}"
- arguments_type = :restful_authentication if #{options[:transition_from_restful_authentication].inspect}
- end
+ arguments_type = (#{options[:act_like_restful_authentication].inspect} && index == 0) ||
+ (#{options[:transition_from_restful_authentication].inspect} && index > 0 && encryptor == Authlogic::CryptoProviders::Sha1) ?
+ :restful_authentication : nil
if encryptor.matches?(#{options[:crypted_password_field]}, *encrypt_arguments(attempted_password, arguments_type))
# If we are transitioning from an older encryption algorithm and the password is still using the old algorithm
# then let's reset the password using the new algorithm. If the algorithm has a cost (BCrypt) and the cost has changed, update the password with
# the new cost.
- if encryptor == #{options[:transition_from_crypto_provider].inspect} || (encryptor.respond_to?(:cost_matches?) && !encryptor.cost_matches?(#{options[:crypted_password_field]}))
+ if index > 0 || (encryptor.respond_to?(:cost_matches?) && !encryptor.cost_matches?(#{options[:crypted_password_field]}))
update_#{options[:password_field]}(attempted_password)
save(false)
end
View
2  lib/authlogic/version.rb
@@ -44,7 +44,7 @@ def to_a
MAJOR = 1
MINOR = 3
- TINY = 3
+ TINY = 4
# The current version as a Version instance
CURRENT = new(MAJOR, MINOR, TINY)
View
6 test/orm_adapters_tests/active_record_adapter_tests/acts_as_authentic_tests/config_test.rb
@@ -44,7 +44,8 @@ def test_acts_as_authentic_config
:password_field_validates_confirmation_of_options => {},
:validate_email_field => true,
:validation_options => {},
- :login_field_validation_options => {}
+ :login_field_validation_options => {},
+ :transition_from_crypto_provider => []
}
assert_equal default_config, User.acts_as_authentic_config
end
@@ -97,7 +98,7 @@ def test_act_like_restful_authentication
def test_transition_from_restful_authentication
User.acts_as_authentic(:transition_from_restful_authentication => true)
assert_equal Authlogic::CryptoProviders::Sha512, User.acts_as_authentic_config[:crypto_provider]
- assert_equal Authlogic::CryptoProviders::Sha1, User.acts_as_authentic_config[:transition_from_crypto_provider]
+ assert_equal [Authlogic::CryptoProviders::Sha1], User.acts_as_authentic_config[:transition_from_crypto_provider]
end
private
@@ -111,6 +112,7 @@ def restore_default_configuration
def convert_password_to(crypto_provider, *records)
User.acts_as_authentic(:crypto_provider => crypto_provider, :transition_from_crypto_provider => Authlogic::CryptoProviders::Sha512)
+ assert_equal [Authlogic::CryptoProviders::Sha512], User.acts_as_authentic_config[:transition_from_crypto_provider]
records.each do |record|
old_hash = record.crypted_password
assert record.valid_password?(password_for(record))
Please sign in to comment.
Something went wrong with that request. Please try again.