I'm trying to hash + salt user passwords with the Bcrypt library that ships with Crystal.
The following code produces an "Invalid salt size" error, when run in a playground.
require "crypto/bcrypt"
user = "Jones"
pass = "password"
temp = Crypto::Bcrypt.new(pass, user)
Use the Crypto::Bcrypt::Password
API, don't directly use Crypto::Bcrypt
.
You don't use the username in the BCrypt hash generation, the API will use a random value as the salt.
bcryptHash = Crypto::Bcrypt::Password.create("password123")
See https://crystal-lang.org/api/master/Crypto/Bcrypt/Password.html