validating password format in Authlogic

故事扮演 提交于 2019-12-05 07:51:44

requires no monkey-patching, but not tied to any future Authlogic changes. Just add this to your User model:

validates_format_of :password, :with => /^(?=.\d)(?=.([a-z]|[A-Z]))([\x20-\x7E]){6,40}$/, :if => :require_password?, :message => "must include one number, one letter and be between 6 and 40 characters"

Of course you can alter the regex to suite your needs.

You can use the configuration options given by acts_as_authentic like so:

    # Configuration is easy:
    #
    #   acts_as_authentic do |c|
    #     c.my_configuration_option = my_value
    #   end
    #
    # See the various sub modules for the configuration they provide.

If you go to the modules in the gem you can see additional options they provide. For example if I want to change the default options of the password's length validation:

acts_as_authentic do |c|
 c.merge_validates_length_of_password_field_options({:minimum => 3})
end

You can look inside the acts_as_authentic folder in your "(gems || plugins)/authlogic/acts_as_authentic/" directory for more options. Cheers!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!