Skip to content

Instantly share code, notes, and snippets.

@murilomothsin
Forked from estum/user.rb
Last active August 29, 2015 14:27
Show Gist options
  • Save murilomothsin/c4abf8785e907e9e8184 to your computer and use it in GitHub Desktop.
Save murilomothsin/c4abf8785e907e9e8184 to your computer and use it in GitHub Desktop.
Migrate passwords from legacy systems to Devise
# 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