Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add type restriction to Crypto::Bcrypt::Password#== #6356

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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