1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Revert "[#4245] Allowing password to nil (#4261)"

This reverts commit 3aedbf0a4d.
This commit is contained in:
Marcos Ferreira 2019-03-26 10:29:46 -03:00
parent e704221842
commit f9d13f015a
2 changed files with 5 additions and 14 deletions

View file

@ -60,18 +60,17 @@ module Devise
# 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.
def valid_password?(password)
return false if password.blank?
Devise::Encryptor.compare(self.class, encrypted_password, password)
end
# Set password and password confirmation to nil
def clean_up_passwords
@password = @password_confirmation = nil
self.password = self.password_confirmation = nil
end
# Update record attributes when :current_password matches, otherwise
@ -199,7 +198,6 @@ module Devise
# See https://github.com/plataformatec/devise-encryptable for examples
# of other hashing engines.
def password_digest(password)
return if password.blank?
Devise::Encryptor.digest(self.class, password)
end

View file

@ -117,9 +117,9 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
assert_nil user.authenticatable_salt
end
test 'should set encrypted password to nil if password is nil' do
assert_nil new_user(password: nil).encrypted_password
assert_nil new_user(password: '').encrypted_password
test 'should not generate a hashed password if password is blank' do
assert_blank new_user(password: nil).encrypted_password
assert_blank new_user(password: '').encrypted_password
end
test 'should hash password again if password has changed' do
@ -307,11 +307,4 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
]
end
end
test 'nil password should be invalid if password is set to nil' do
user = User.create(email: "HEllO@example.com", password: "12345678")
user.password = nil
refute user.valid_password?('12345678')
refute user.valid_password?(nil)
end
end