class Crypto::Bcrypt::Password
inherits Reference
¶
Generate, read and verify Crypto::Bcrypt
hashes.
require "crypto/bcrypt/password"
password = Crypto::Bcrypt::Password.create("super secret", cost: 10)
# => $2a$10$rI4xRiuAN2fyiKwynO6PPuorfuoM4L2PVv6hlnVJEmNLjqcibAfHq
password.verify("wrong secret") # => false
password.verify("super secret") # => true
See Crypto::Bcrypt
for hints to select the cost when generating hashes.
Class methods¶
.create(password, cost = DEFAULT_COST) : self
¶
(password, cost = DEFAULT_COST) : self
Hashes a password.
require "crypto/bcrypt/password"
password = Crypto::Bcrypt::Password.create("super secret", cost: 10)
# => $2a$10$rI4xRiuAN2fyiKwynO6PPuorfuoM4L2PVv6hlnVJEmNLjqcibAfHq
.new(raw_hash : String)
¶
(raw_hash : String)
Loads a bcrypt hash.
require "crypto/bcrypt/password"
password = Crypto::Bcrypt::Password.new("$2a$10$X6rw/jDiLBuzHV./JjBNXe8/Po4wTL0fhdDNdAdjcKN/Fup8tGCya")
password.version # => "2a"
password.salt # => "X6rw/jDiLBuzHV./JjBNXe"
password.digest # => "8/Po4wTL0fhdDNdAdjcKN/Fup8tGCya"
Methods¶
#inspect(io : IO) : Nil
¶
(io : IO) : Nil
Appends a String representation of this object which includes its class name, its object address and the values of all instance variables.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).inspect # => #<Person:0x10fd31f20 @name="John", @age=32>
#to_s(io : IO) : Nil
¶
(io : IO) : Nil
Appends a short String representation of this object which includes its class name and its object address.
class Person
def initialize(@name : String, @age : Int32)
end
end
Person.new("John", 32).to_s # => #<Person:0x10a199f20>
#verify(password : String) : Bool
¶
(password : String) : Bool
Verifies a password against the hash.
require "crypto/bcrypt/password"
password = Crypto::Bcrypt::Password.create("super secret")
password.verify("wrong secret") # => false
password.verify("super secret") # => true