Created
October 5, 2012 15:47
-
-
Save jystewart/3840618 to your computer and use it in GitHub Desktop.
Methods for migrating devise passwords from naive MD5 to a new strategy
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
class User < ActiveRecord::Base | |
alias_method :valid_password_without_legacy?, :valid_password? | |
def valid_password?(incoming_password) | |
if valid_password_without_legacy?(incoming_password) | |
return true | |
elsif Digest::MD5.hexdigest(incoming_password) == self.encrypted_password | |
update_legacy_password(incoming_password) | |
end | |
end | |
def update_legacy_password(incoming_password) | |
self.password = incoming_password | |
self.encrypted_password = password_digest(@password) | |
save! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment