Migrating Legacy Users with Devise

01 Feb 2012

I’m currently working to replace an older legacy app with a Rails 3 app using Devise for authentication. One of the problems we encountered was was that the legacy app was using a non-standard approach for generating and encrypting passwords, so to migrate over user accounts, Devise’s built-in encryption strategies were completely useless. Fortunately, it turns out in Devise it is incredibly easy to build your own encryptor.

Basically, all you have to do is create an file in config/initializers like the following:

Then, in your config/initializers/devise.rb, its as simple as adding (or editing) a line that references the class you created.

As long as your encryptor returned the encrypted version of your password, you’re good to go.

Now migrating your accounts should be fairly straightforward. We were using restful auth in the legacy app, so I just mapped the important differences and then converted the passwords (being sure to save with false, in order to bypass devise validations)

comments powered by Disqus