Skip to content

Commit

Permalink
:transition_from_crypto_provider now accepts an array
Browse files Browse the repository at this point in the history
  • Loading branch information
binarylogic committed Nov 25, 2008
1 parent ae44442 commit ca2b972
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
6 changes: 5 additions & 1 deletion 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 --
Expand Down
Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/authlogic/version.rb
Expand Up @@ -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)
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit ca2b972

Please sign in to comment.