BCrypt::Password
Constructors
create(password, cost = Crypto::Bcrypt::DEFAULT_COST) : self
Hashes a password.
require "crypto/bcrypt/password"
password = BCrypt::Password.create("super secret", cost: 10)
# => $2a$10$rI4xRiuAN2fyiKwynO6PPuorfuoM4L2PVv6hlnVJEmNLjqcibAfHq
new(raw_hash : String)
Loads a bcrypt hash.
require "crypto/bcrypt/password"
password = BCrypt::Password.new("$2a$10$X6rw/jDiLBuzHV./JjBNXe8/Po4wTL0fhdDNdAdjcKN/Fup8tGCya")
password.version # => "2a"
password.salt # => "X6rw/jDiLBuzHV./JjBNXe"
password.digest # => "8/Po4wTL0fhdDNdAdjcKN/Fup8tGCya"
Instance methods
cost
Sourcedigest
SourceAppends this struct's name and instance variables names and values to the given IO.
struct Point
def initialize(@x : Int32, @y : Int32)
end
end
p1 = Point.new 1, 2
p1.to_s # "Point(@x=1, @y=2)"
p1.inspect # "Point(@x=1, @y=2)"
salt
SourceVerifies a password against the hash.
require "crypto/bcrypt/password"
password = BCrypt::Password.create("super secret")
password.verify("wrong secret") # => false
password.verify("super secret") # => true
version
Source