mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
Avoid BCrypt::Errors::InvalidSalt: invalid salt
when password_salt is nil. Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
parent
5429f940e7
commit
c121d8026e
3 changed files with 16 additions and 1 deletions
|
@ -81,8 +81,10 @@ module Devise
|
||||||
|
|
||||||
# Digests the password using the configured encryptor.
|
# Digests the password using the configured encryptor.
|
||||||
def password_digest(password)
|
def password_digest(password)
|
||||||
|
if self.password_salt.present?
|
||||||
self.class.encryptor_class.digest(password, self.class.stretches, self.password_salt, self.class.pepper)
|
self.class.encryptor_class.digest(password, self.class.stretches, self.password_salt, self.class.pepper)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
Devise::Models.config(self, :pepper, :stretches, :encryptor)
|
Devise::Models.config(self, :pepper, :stretches, :encryptor)
|
||||||
|
|
|
@ -98,6 +98,13 @@ class DatabaseAuthenticatableTest < ActiveSupport::TestCase
|
||||||
assert_not user.valid_password?('654321')
|
assert_not user.valid_password?('654321')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'should not validate password when salt is nil' do
|
||||||
|
admin = create_admin
|
||||||
|
admin.password_salt = nil
|
||||||
|
admin.save
|
||||||
|
assert_not admin.valid_password?('123456')
|
||||||
|
end
|
||||||
|
|
||||||
test 'should respond to current password' do
|
test 'should respond to current password' do
|
||||||
assert new_user.respond_to?(:current_password)
|
assert new_user.respond_to?(:current_password)
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,6 +37,12 @@ class ActiveSupport::TestCase
|
||||||
User.create!(valid_attributes(attributes))
|
User.create!(valid_attributes(attributes))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def create_admin(attributes={})
|
||||||
|
valid_attributes = valid_attributes(attributes)
|
||||||
|
valid_attributes.delete(:username)
|
||||||
|
Admin.create!(valid_attributes)
|
||||||
|
end
|
||||||
|
|
||||||
# Execute the block setting the given values and restoring old values after
|
# Execute the block setting the given values and restoring old values after
|
||||||
# the block is executed.
|
# the block is executed.
|
||||||
def swap(object, new_values)
|
def swap(object, new_values)
|
||||||
|
|
Loading…
Reference in a new issue