I'm using the gem "bcrypt". It's a Rack app. Once I've created a password hash and stored it in my db,
# register a user
plain_pass = get_input_from_user
pass_hash = BCrypt::Password.create(params["pass"])
# store in db
# ......
how can I then compare to the plain that comes from a user?
email = get_user_email
usr = User.first(email: params["email"])
plain_pass = params["pass"]
pass_hash = ?????
if usr.pass_hash == pass_hash
# ok, all good
The issue is that Password.create
creates a new password each time, even with the same input:
irb(main):038:0> BCrypt::Password.create("aaa")
=> "$2a$10$CCWMcREb5mP2ldFshb4qiua.VK2ABHXCtDSzj2WwYf/KsZQjoDGoO"
irb(main):039:0> BCrypt::Password.create("aaa")
=> "$2a$10$w9rAu9FmLZ/jQ7IQmXutW.nh272ucS0PsIrMYUMBrDQpt4U70wOqa"