Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise allows blank password during password reset

I have a Rails 3.2 app setup with Devise. Everything works great except for when I reset a password ( via the built in routes and methods ), Devise is allowing a blank password. It will validate the length and if it matches the confirmation if there is at least one character. I do have it setup where in a users account they can update their profile without entering the password, but I don't think that has anything to do with resetting the password.

Any help is appreciated.

devise.rb -> http://pastie.org/3911178

user.rb -> http://pastie.org/3911187

like image 832
John Goodman Avatar asked Feb 21 '23 12:02

John Goodman


1 Answers

Thanks for pointing me in the right direction. The problem was caused by what you described. However, if I let devise handle the validation or use the same code they do, the user must provide a password when updating their account even after they are logged in. To fix this, I just checked for the rest_password_token in my validation:

def password_required?
  # If resetting the password
  return true if reset_password_token.present? && reset_password_period_valid?

   # If the person already has a pass, only validate if they are updating pass
  if !encrypted_password.blank?
    password.present? || password_confirmation.present?
  end
end

*UPDATE I just updated this to ensure the password token is not expired.

like image 194
John Goodman Avatar answered Feb 23 '23 07:02

John Goodman