Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not set encrypted_password to nil if password is blank #5044

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/devise/models/database_authenticatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def self.required_fields(klass)
# the hashed password.
def password=(new_password)
@password = new_password
self.encrypted_password = password_digest(@password)
self.encrypted_password = password_digest(@password) if @password.present?
end

# Verifies whether a password (ie from sign in) is the user password.
Expand Down
6 changes: 6 additions & 0 deletions test/models/database_authenticatable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ def setup
assert_nil new_user(password: '').encrypted_password
end

test 'should not set encrypted password to nil if updating with blank password' do
user = create_user
user.password = ''
refute_nil user.encrypted_password
end

test 'should hash password again if password has changed' do
user = create_user
encrypted_password = user.encrypted_password
Expand Down