これで問題が解決すると思います:
$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!'; }
BCrypt::Password.create(desired_pass)
これは、Rubyを使用してそれらを保存し、 BCrypt::Password.new(database_entry) == form_input
.
さらに、データベースに新しいパスワード (つまり、新しいユーザー) を作成するには、次の結果を保存します。
$password = crypt($user_input, '$2a$10$usesomesillystringforsalt$');
最後に、常に正しい原価係数を使用していることを確認してください。コスト要因が異なる同じパスワードは同等ではありません。bcrypt-ruby のデフォルトのコスト係数は 10 (現在のバージョン、3.0.1) です。