struct

BCrypt::Password

Inherits Struct < Value < Object

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
Source
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"
Source

Instance methods

cost
Source
digest
Source
inspect(io : IO) : Nil

Appends 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)"
Source
parse_cost(slice : Bytes)
Source
salt
Source
to_s(io : IO) : Nil

Same as #inspect(io).

Source
verify(password : String) : Bool

Verifies 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
Source
version
Source