直接從Rails的API
# Schema: User(name:string, password_digest:string)
class User < ActiveRecord::Base
has_secure_password
end
user = User.new(:name => "david", :password => "", :password_confirmation => "nomatch")
user.save # => false, password required
user.password = "mUc3m00RsqyRe"
user.save # => false, confirmation doesn't match
user.password_confirmation = "mUc3m00RsqyRe"
user.save # => true
user.authenticate("notright") # => false
user.authenticate("mUc3m00RsqyRe") # => user
您需要在您的哈希:password_confirmation => "pass
!
對,所以看看has_secure_password
你想要執行BCrypt::Password.create(unencrypted_password)
來獲得它。您需要使用bcrypt-ruby
寶石來完成上述操作。
謝謝!我忘了BCrypt,它沒有密碼確認太好:) –
真棒,很高興聽到它=) –