Created
January 30, 2012 14:16
-
-
Save moeffju/1704632 to your computer and use it in GitHub Desktop.
This file contains 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 :devise_valid_password? :valid_password? | |
def valid_password?(password) | |
begin | |
devise_valid_password?(password) | |
rescue BCrypt::Errors::InvalidHash | |
return false unless Digest::SHA1.hexdigest(password) == encrypted_password | |
logger.info "User #{email} is using the old password hashing method, updating attribute." | |
self.password = password | |
true | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for great example! You saved me some time today :-)
One more tip. If you are using salt in legacy user, its also good to clear that value. This way you will know how many users has already been updated. And I also had to manually save loaded object.