Skip to content

Commit

Permalink
Merge pull request #6356 from straight-shoota/jm/fix/bcrypt-password-eq
Browse files Browse the repository at this point in the history
Fix: Add type restriction to Crypto::Bcrypt::Password#==
  • Loading branch information
ysbaddaden authored Jul 9, 2018
2 parents afeaee4 + ad5fb0a commit 9ba6ba9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions spec/std/crypto/bcrypt/password_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,16 @@ describe "Crypto::Bcrypt::Password" do
it "verifies password is correct" do
(password == "secret").should be_true
end

it "works with Password" do
(password == password).should be_true

other_password = Crypto::Bcrypt::Password.create("wrong", 4)
(password == other_password).should be_false
end

it "works with other types" do
(password == 0.815).should be_false
end
end
end
2 changes: 1 addition & 1 deletion src/crypto/bcrypt/password.cr
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Crypto::Bcrypt::Password
# password == "wrong secret" # => false
# password == "super secret" # => true
# ```
def ==(password)
def ==(password : String) : Bool
hashed_password = Bcrypt.new(password, salt, cost)
Crypto::Subtle.constant_time_compare(@raw_hash, hashed_password)
end
Expand Down

0 comments on commit 9ba6ba9

Please sign in to comment.