我刚刚开始使用MongoDB,特别是Mongoid.
自然,我想确保我User的密码保持良好和安全,以前我会这样做ActiveRecord并使用bcrypt. 我正在寻找一种漂亮、干净、安全、简单的方法来使用Mongoid.
我已经查看了mongoid-encryptor,但我还没有完全了解如何使用它。
假设我的简化User看起来像这样,根据mongoid-encryptor自述文件中的示例。
class User
include Mongoid::Document
include Mongoid::Encryptor
field :name
field :password
encrypts :password
end
在我的 WebApp 中(Sinatra在这种情况下使用)我会定义一个助手,例如
def login (name, cleartxtpass)
return User.where(name: name, password: cleartxtpass).first
end
- 我如何使用它
bcrypt? - 是否有任何预处理我需要做
cleartxtpass或Mongoid::Encryptor只处理?从文档中不清楚。