↖️ Show all posts

BCrypt in Ruby

I stumbled across this post from Kieran, that explains bang on how BCrypt works.

# Create hash of password
pass = BCrypt::Password.create('TestPassword') => "$2a$10$3.D6D2htbiRrezmZUhePV.gaQlc3ZjFYD9hv43khN5eWP5y8BGUXG"

# Pass the hash you have stored to Password.new
db_hash = BCrypt::Password.new("$2a$10$3.D6D2htbiRrezmZUhePV.gaQlc3ZjFYD9hv43khN5eWP5y8BGUXG")

# Compare the input from the user to the password stored
db_hash == "TestPassword" => true
db_hash == "NotRealPassword" => false

Additionally check out the gem’s excellent docs on github.


⬅️ Read previous Read next ➡️