0

restful_authentication でパスワードの最小長を変更する方法はありますか? 現在は 6 文字ですが、別の値が必要です。

このように Authentication::ByPassword の前後に validates_length_of を呼び出してみました

validates_length_of :password, :within => 4..40, :if => :password_required?  
include Authentication::ByPassword

そしてこのように:

include Authentication::ByPassword
validates_length_of :password, :within => 4..40, :if => :password_required?  

ただし、最小パスワードは 6 のままでした。

4

2 に答える 2

0

ActsAsAuthenticには、次のような構成オプションがあります。

acts_as_authentic do |config|
  config.merge_validates_length_of_password_field_options       :within => 4..40
  config.merge_validates_confirmation_of_password_field_options :within => 4..40
end

残念ながら、RestfulAuthentication にはこれらの構成オプションがありません。正しい解決策は、 RestfulAuthenticationプロジェクトをフォークして追加することです。

それまでの間、次のようにモンキー パッチを適用できますAuthentication::ByPassword.included

# in app/models/user.rb:
Authentication::ByPassword.class_eval do
  def self.included(base)
    recipient.extend(ModelClassMethods)
    recipient.class_eval do
      include ModelInstanceMethods

      # Virtual attribute for the unencrypted password
      attr_accessor :password
      validates_presence_of :password, :if => :password_required?
      validates_presence_of :password_confirmation, :if => :password_required?
      validates_confirmation_of :password, :if => :password_required?
      validates_length_of :password, :within => 4..40, :if => :password_required?
      before_save :encrypt_password
    end
  end
end
于 2010-04-20T13:18:04.507 に答える
0

vendor/plugins/restful-authentication/lib/authentication/by_password.rb に移動して、この文字列を編集します

validates_length_of :password, :within => 6..40, :if => :password_required?
于 2010-04-20T12:46:52.783 に答える