I'm reworking a website in Rails using Devise for authentication. The previous website works with a database of users with md5 passwords, and therefore I want to migrate this passwords to the encryption that Devise using. How do I solve it?
相关问题
- facebook error invalid key hash for some devices
- Strong parameter override for DeviseTokenAuth cont
- Eager-loading association count with Arel (Rails 3
- Change first key of multi-dimensional Hash in perl
- Rails simple model attributes not saved to databas
相关文章
- “No explicit conversion of Symbol into String” for
- Rspec controller error expecting <“index”> but
- Factory_girl has_one relation with validates_prese
- Bcrypt vs Hash in laravel
- Rails: Twitter Bootstrap Buttons when visited get
- is there a “rails” way to redirect if mobile brows
- Got ActiveRecord::AssociationTypeMismatch on model
- superclass mismatch for class CommentsController (
I have an alternative solution:
plain text->md5->bcrypt
.This way all passwords can be migrated at once and MD5 hashes discarded permanently. Considering doing this myself, can't pick any faults with this idea. Any takers? Am I missing something obvious?
There is no way to convert an md5 hash into another kind of hash. You will have to make users log in using the old system, and then hash the password they give using the new method. Once you have the new hash, you can delete the old, md5 hash.
Oleksi and josnidhin did a great job at answering your question. I just wanted to add some ideas what to do during the transition phase:
Migrate the DB towards having two "password hash" columns, one containing the existing old MD5 hashes, and another one for the new bcrypt hashes, initially all filled with NULL. The next time a user logs in, you do these steps:
1) Check if there's already a value in the bcrypt column. If so continue with 3., otherwise with 2.
2) Authenticate the user with the old MD5 mechanism using the value from the MD5 column. If successful, additionally compute the new bcrypt hash and store it in the new column. Done.
3) Authenticate the user using the brypt value. Simply ignore the MD5 value.
Then from time to time, check whether the new bcrypt column is filled. If so, discard the MD5 column and update your app to only use the new mechanism.
But that's wishful thinking, there are always some users that haven't logged in in the meantime. Send them a mail telling them what you are doing, that it's for their best and ask them kindly to log in soon.
After a couple of weeks, check the bcrypt status again. If there's still some passwords missing (there will be :)), what you could do is to just reset the passwords of these users, generate a random one and informing them via mail, much like what you would do if they forgot their passwords.
Then, you can finally purge the MD5 column, discard the corresponding code and upgrade your app to only use the new authentication.
You will have to ask the user to login using the old password and then change it for example show a compulsory change password page which will store the password using bcrypt. Once the new password is given you could disable/delete the old password in you system.