I am trying to implement a method so that in some way the password is replaced by any other service. .
# Change profile password def change_password (oldpass, newpass) pepper = nil cost = 10 # Encrypt plain text passwords encrypt_old = :: BCrypt :: Password.create ("# {oldpass} # {Pepper} ",: cost = & gt; cost) .to_s # Confirm old if self.encrypted_password == encrypt_old encrypt_new = :: BCrypt :: Password.create (" # {newpass} # {pepper} ", cost = & Gt; Cost) .to_s itself .encrypted_password = encrypt_new self.save else Logger.new ("wrong old password!") End of End It seems that I have password encryption wrong Is old code in oldpass, which is a plain text Sector should see whether it matches the current password, then allow to store the new password. However, what I am getting is the wrong password.
Re-work:
def change_password (oldpass, newpass) if valid_password? (Oldpass) password = Last
at the end of return Not required, if you are in the app or in the rail console.
Just update the user in the following ways and the device will take care of itself.
user.password = new_password user.save The division will then encrypt the password and store it. You must ensure that user.password_confirmation is zero . If there is anything password_confirmation , then it will be matched against password . Edit You can test the current password like this: user.valid_password? (Old_password)
No comments:
Post a Comment