LoginSignup
1

More than 5 years have passed since last update.

bcrypt→deviseに既存システムのログイン周りを変更。DBを引き継ぐためにしたこと。

Last updated at Posted at 2019-03-09

やり方

①deviseを導入する。
②password_digestカラムをencrypted_passwordにリネームする。

具体的には、以下のコマンドでuserモデルを変更する。

rails g migration rename_password_digest_column_to_encrypted_password
class RenamePasswordDigestColumnToEncryptedPassword < ActiveRecord::Migration
  def change
    rename_column :password_digest, :encrypted_password, :users #テーブル名の指定を忘れない!!
  end
end

やりたかったこと

既存システムのログイン周りを、bcryptを使用した全部手書きからdeviseログインに移行。DBのデータは引き継ぐ。

なんでしたかったの

2000人くらい登録者がいるサービスのログインとかセッションをdeviseに任せたくなった(初心者なので作った時devise知らなかった)

なんでできるの

デバイスもパスワードの暗号化にbcryptを使っているので、暗号化されたカラム名だけが異なる。

なのでカラム名を変更してあげればok。

注意

ユーザーは再度ログインが必要になる。大した問題ではないだろう。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1