when I create users (in sinatra), I do this
require 'Bcrypt'
post '/users' do
@user = User.new(params[:user])
@user.password_hash = BCrypt::Password.create(params[:password])
p @user.password_hash == params[:password] # this prints TRUE!
@user.save!
session[:user_id] = @user.id
redirect '/'
end
then when I try to verify the same user I get this
post '/sessions' do
@user = User.find_by_email(params[:email])
p @user.id # prints 14
p @user.password_hash # prints correct hash
p @user.password_hash.class # prints String
p BCrypt::Password.new(@user.password_hash).class # prints BCrypt::Password
p params[:password] # prints "clown123"
p BCrypt::Password.new(@user.password_hash) == params[:password] # prints FALSE!
# redirect '/'
end
What broke? The example given in the BCrypt docs (which doesn't use a database) works every time. Could something in my db (postgres) be altering the password_hash?
using the very latest version of bcrypt, and ruby 1.9.3 (I've tried ruby 2.0 and up as well with the same results)