Skip to content
Closed
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
12 changes: 10 additions & 2 deletions lib/bcrypt/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,17 @@ def initialize(raw_hash)
end
end

# Compares a potential secret against the hash. Returns true if the secret is the original secret, false otherwise.
# Compares a potential secret against the hash using a constant-time comparison function. Returns true if the secret
# is the original secret, false otherwise.
def ==(secret)
super(BCrypt::Engine.hash_secret(secret, @salt))
hash = BCrypt::Engine.hash_secret(secret, @salt)

return false if hash.strip.empty? || strip.empty? || hash.bytesize != bytesize
l = hash.unpack "C#{hash.bytesize}"

res = 0
each_byte { |byte| res |= byte ^ l.shift }
res == 0
end
alias_method :is_password?, :==

Expand Down