Skip to content
Merged
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
9 changes: 8 additions & 1 deletion lib/bcrypt/password.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,14 @@ def initialize(raw_hash)
#
# secret == @password # => probably False, because the secret is not a BCrypt::Password instance.
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

# Constant time comparison so they can't tell the length.
res = 0
bytesize.times { |i| res |= getbyte(i) ^ hash.getbyte(i) }
res == 0
end
alias_method :is_password?, :==

Expand Down