LoginSignup
40
29

More than 5 years have passed since last update.

deviseでパスワードの最低文字数を変更する方法。

Last updated at Posted at 2019-03-05

パスワードを変更するには2種類の方法があります。

1 railsアプリのルートディレクトリ直下の~/configディレクトリにあるファイルを編集する方法です。

~/config/initializers/devise.rbにアクセスしてください。

config.password_length = 6..128

上記の部分がファイルの真ん中らへんにあるので、数値の部分を変更してください。

2 deviseを使用するモデルに直接記述する方法です。

例えば、user.rbに

devise :validatable, password_length: 10..128

このようにpassword_length: で指定してあげましょう。

最後に

自分でモデルにvalidates :password, length: { maximum: 8 }みたいに指定するとエラーの元になるのでやめましょう。僕はこれで1時間くらい溶かしました。

参考文献
https://github.com/plataformatec/devise/wiki/Customize-minimum-password-length

40
29
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
40
29