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 @@ -119,7 +119,7 @@ def initialize(attribute)
119
119
# user.authenticate_password('mUc3m00RsqyRe') # => user
120
120
define_method ( "authenticate_#{ attribute } " ) do |unencrypted_password |
121
121
attribute_digest = public_send ( "#{ attribute } _digest" )
122
- BCrypt ::Password . new ( attribute_digest ) . is_password? ( unencrypted_password ) && self
122
+ attribute_digest . present? && BCrypt ::Password . new ( attribute_digest ) . is_password? ( unencrypted_password ) && self
123
123
end
124
124
125
125
alias_method :authenticate , :authenticate_password if attribute == :password
Original file line number Diff line number Diff line change @@ -218,6 +218,11 @@ class SecurePasswordTest < ActiveModel::TestCase
218
218
assert_equal @user , @user . authenticate_recovery_password ( "42password" )
219
219
end
220
220
221
+ test "authenticate should return false and not raise when password digest is blank" do
222
+ @user . password_digest = " "
223
+ assert_equal false , @user . authenticate ( " " )
224
+ end
225
+
221
226
test "Password digest cost defaults to bcrypt default cost when min_cost is false" do
222
227
ActiveModel ::SecurePassword . min_cost = false
223
228
You can’t perform that action at this time.
0 commit comments