Skip to content

Instantly share code, notes, and snippets.

@jystewart
Created October 5, 2012 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jystewart/3840618 to your computer and use it in GitHub Desktop.
Save jystewart/3840618 to your computer and use it in GitHub Desktop.
Methods for migrating devise passwords from naive MD5 to a new strategy
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