4
當我創建的用戶(在西納特拉),我這樣做爲什麼BCrypt無法在此情況下進行身份驗證?
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
然後當我嘗試驗證相同的用戶我得到這個
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
什麼突破? BCrypt文檔(不使用數據庫)中給出的示例每次都有效。 可以在我的分貝(postgres)的東西改變密碼?哈希?使用
的最新版本bcrypt的,和Ruby 1.9.3(我試過紅寶石2.0和行動,以及具有相同的結果)
感謝 - 原來我的PARAMS是從我的註冊表中以奇怪的方式進入,問題不在於我的數據庫 – dwilbank