Skip to content

Commit

Permalink
Add Crypto::Bcrypt::Password#==
Browse files Browse the repository at this point in the history
Previously, it used `Reference` equality, which compares identity rather
than value.
  • Loading branch information
jgaskins committed Dec 12, 2024
1 parent ee69981 commit abdb585
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/std/crypto/bcrypt/password_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,13 @@ describe "Crypto::Bcrypt::Password" do
(password2y.verify "secret").should be_true
end
end

describe "#==" do
it "is equal if the string representations are equal" do
canonical = Crypto::Bcrypt::Password.create("secret", 4)
challenge = Crypto::Bcrypt::Password.new(canonical.to_s)

canonical.should eq challenge
end
end
end
2 changes: 2 additions & 0 deletions src/crypto/bcrypt/password.cr
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,6 @@ class Crypto::Bcrypt::Password
def inspect(io : IO) : Nil
to_s(io)
end

def_equals_and_hash
end

0 comments on commit abdb585

Please sign in to comment.