File tree Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ def initialize(attribute)
118
118
# user.authenticate_password('mUc3m00RsqyRe') # => user
119
119
define_method ( "authenticate_#{ attribute } " ) do |unencrypted_password |
120
120
attribute_digest = public_send ( "#{ attribute } _digest" )
121
- BCrypt ::Password . new ( attribute_digest ) . is_password? ( unencrypted_password ) && self
121
+ attribute_digest . present? && BCrypt ::Password . new ( attribute_digest ) . is_password? ( unencrypted_password ) && self
122
122
end
123
123
124
124
alias_method :authenticate , :authenticate_password if attribute == :password
Original file line number Diff line number Diff line change @@ -212,6 +212,11 @@ class SecurePasswordTest < ActiveModel::TestCase
212
212
assert_equal @user , @user . authenticate_recovery_password ( "42password" )
213
213
end
214
214
215
+ test "authenticate should return false and not raise when password digest is blank" do
216
+ @user . password_digest = " "
217
+ assert_equal false , @user . authenticate ( " " )
218
+ end
219
+
215
220
test "Password digest cost defaults to bcrypt default cost when min_cost is false" do
216
221
ActiveModel ::SecurePassword . min_cost = false
217
222
You can’t perform that action at this time.
0 commit comments