Mongoid和has_secure_password

时间:2011-08-03 02:01:04

标签: authentication mongoid ruby-on-rails-3.1

我正在尝试使用mongoid而不是活动模型来使用rails 3.1身份验证

 class User 
  include Mongoid::Document
  include ActiveModel::SecurePassword
  has_secure_password  
  validates_presence_of :password, :on => :create
  attr_accessor :email, :password, :password_confirmation 
  field :email, :type => String
  field :password_digest, :type => String
 end

问题是bycrypt无法识别password_digest,如活动模型示例http://railscasts.com/episodes/270-authentication-in-rails-3-1

由于

2 个答案:

答案 0 :(得分:34)

对于任何感兴趣的人,使用has_secure_password与Mongoid的最低要求只是在模型中包含ActiveModel::SecurePassword

class User
  include Mongoid::Document
  include ActiveModel::SecurePassword

  field :username
  field :password_digest

  has_secure_password
end

Article

答案 1 :(得分:5)

has_secure_password

field :password_digest, :type => String