Last active
December 21, 2015 05:49
-
-
Save estum/6259863 to your computer and use it in GitHub Desktop.
Migrate passwords from legacy systems to Devise
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
# updated variant of older solution: | |
# http://www.davidverhasselt.com/2012/05/13/how-to-migrate-passwords-from-legacy-systems-to-devise | |
class User < ActiveRecord::Base | |
# ... | |
def valid_password?(password) | |
if legacy_password? | |
# Use Devise's secure_compare to avoid timing attacks | |
return false unless super User.legacy_password(password) | |
self.attributes = { password: password, password_confirmation: password, legacy_password: false } | |
self.save! | |
end | |
super password | |
end | |
# Put your legacy password hashing method here | |
def self.legacy_password(password) | |
return Digest::MD5.hexdigest("#{password}-salty-herring"); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment