Devise: Disable password confirmation during sign-up

后端 未结 9 879
走了就别回头了
走了就别回头了 2020-12-24 01:13

I am using Devise for Rails. In the default registration process, Devise requires users to type the password twice for validation and authentication. How can I disable it?

相关标签:
9条回答
  • 2020-12-24 02:00

    Simplest solution:

    Remove :validatable from

    devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable,
     :confirmable, :timeoutable, :validatable
    

    ;)

    0 讨论(0)
  • 2020-12-24 02:02

    I think this is the simple way to disable password confirmation: https://github.com/plataformatec/devise/wiki/Disable-password-confirmation-during-registration

    Some users wants to make the registration process shorter and easier. One of fields that can be removed is the Password confirmation.

    Easiest solution is: you can simply remove the password_confirmation field from the registration form located at devise/registrations/new.html.erb (new.html.haml if you are using HAML), which disables the need to confirm the password entirely!

    The reason for this lies in lib/devise/models/validatable.rb in the Devise source:

    Note that the validation is only triggered if password_required? returns true, and password_required? will return false if the password_confirmation field is nil.

    Because where the password_confirmation field is present in the form, it will always be included in the parameters hash , as an empty string if it is left blank, the validation is triggered. However, if you remove the input from the form, the password_confirmation in the params will be nil, and therefore the validation will not be triggered.

    0 讨论(0)
  • 2020-12-24 02:06

    I am not familiar with Devise but if you have access to the model in the controller before save/validation could you do something like the following

    model.password_confirmation = model.password
    model.save
    
    0 讨论(0)
提交回复
热议问题