LoginSignup
0
0

More than 3 years have passed since last update.

【Rails】Railsのencrypted_passwordを自作する

Posted at

前提

ローカル環境でのテスト用などに、手動でユーザーを作成時のパスワードを生成する。
rails consoleを利用。

作業手順

encrypted_passwordの自作

ターミナル
password = '12345678'
User.new(password: password).encrypted_password

rails cで上記を実行すると、encrypted_passwordが生成される。
この例ではusersテーブルのencrypted_passwordカラムにコピペすると、
'12345678'がパスワードとなる。

確認

ターミナル
user = User.find(1)
user.valid_password?('12345678')

上記のようにrails cから操作すると、
users.id=1のレコードのパスワードが'12345678'であるか確認できる。

0
0
0

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
0
0