I've just started out using MongoDB
and, in particular, Mongoid
.
naturally I'd like to ensure my User
's passwords are kept nice and secure, and previously I'd have done this with ActiveRecord
and used bcrypt
. I'm looking for a nice, clean, secure, simple way to implement the same sort of thing using Mongoid
.
I've taken a look at mongoid-encryptor but I've not quite got my head around how to use it.
Assume my simplified User
looks like this, as per the example in mongoid-encryptor
's Readme file.
class User
include Mongoid::Document
include Mongoid::Encryptor
field :name
field :password
encrypts :password
end
And in my WebApp (using Sinatra
in this case) I'd define a helper such as
def login (name, cleartxtpass)
return User.where(name: name, password: cleartxtpass).first
end
- How do I get it to use
bcrypt
? - Is there any pre-processing I need to do with
cleartxtpass
or willMongoid::Encryptor
just handle that? It's not clear from the docs.