Skip to content

Navigation Menu

Sign up

Disable password confirmation during registration

Rubioli edited this page Mar 1, 2016 · 5 revisions

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:

module Devise module Models module Validatable

 def self.included(base)
 base.class_eval do
 #....SNIP...
 validates_confirmation_of :password, :if => :password_required?
 end
 end
 #...SNIP...
 def password_required?
 !persisted? || !password.nil? || !password_confirmation.nil?
 end
end

end end

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.

Inspired by @mistertim in stackoverflow

Clone this wiki locally

AltStyle によって変換されたページ (->オリジナル) /