I believe this would solve your problem:
$database_record = "something"; // grab from database
$user_input = 'unicorns'; // take real one from post data
$password = crypt($user_input, '$2a$10$usesomesillystringforsalt$');
// key piece above is the second number, that is the 'work' factor
if (crypt($user_input, $database_record) == $password) {
echo "Password verified!";
}
else {
echo 'failed!'; }
This assumes you stored them using BCrypt::Password.create(desired_pass)
in Ruby, and were verifying login by BCrypt::Password.new(database_entry) == form_input
.
Additionally, to create a new password in your database (i.e. a new user), store the result of
$password = crypt($user_input, '$2a$10$usesomesillystringforsalt$');
Lastly, make sure that you are always using the correct cost factor. The same password with different cost factors will not be equivalent. The default cost factor in bcrypt-ruby is 10 (current version, 3.0.1).