ruby on rails - New password is only accepting old password not different password -
in rails 3.2.13 project, using devise plugin. if going change password need enter current_password 3 fields, if try enter different password new_password & confirm_password fields show error message "current password invalid".
i have referred https://github.com/plataformatec/devise/blob/bf5bcd52cb9edaefb002927434d7ede398e74bc5/lib/devise/models/database_authenticatable.rb#l46
in model,
def valid_password?(password) return false if encrypted_password.blank? bcrypt = ::bcrypt::password.new(encrypted_password) password = ::bcrypt::engine.hash_secret("#{password}#{self.class.pepper}", bcrypt.salt) devise.secure_compare(password, encrypted_password) end def update_with_password(params, *options) current_password = params.delete(:current_password) if params[:password].blank? params.delete(:password) params.delete(:password_confirmation) if params[:password_confirmation].blank? end result = if valid_password?(current_password) update_attributes(params, *options) else self.assign_attributes(params, *options) self.valid? self.errors.add(:current_password, current_password.blank? ? :blank : :invalid) false end result end
in controller,
@user.update_with_password(params["user"])
validation should work like,
current password & new password should present
if user enters wrong password in current_password field should check valid or not
new password & confirm password should match
e.g.:
1st case: (shows invalid password message) current password = "password" new password = "abcdefg" confirm password = "abcdefg" 2nd case: (accepts successfully) current password = "password" new password = "password" confirm password = "password"
how can change password entering different password instead of current(old) password?
Comments
Post a Comment