views:

43

answers:

1

I have my own password/login rules that I want to implement such as:

  • Password: At least one number, one lower case character and one upper case character
  • Login: Alphanumeric and between 4 and 15 characters long

etc...

Currently when I do not enter a password and login in my form, I get the following errors (from Authlogic's default validations):

  • Login is too short (minimum is 3 characters)
  • Password is too short (minimum is 4 characters)
  • Password confirmation is too short (minimum is 4 characters)

These validation rules are not in my model, they come from the Authlogic gem. I know there are configurations that I can add using:

acts_as_authentic do |config|
  config.validate_password_field = false
end

The problem is that I can't find good documentation for these configurations and when I try the one above so I can use my own, it complains: undefined method 'password_confirmation' for #<User:0x7f5fac8fe7c0>

Doing this:

acts_as_authentic do |config|
  config.validate_password_field = false

  # added this so it might stop complaining
  config.require_password_confirmation = true
end

Does nothing.

Is there a way to have Authlogic require password confirmation while ignore all other validation so that I can control this?

+1  A: 

The undefined method 'password_confirmation' can be avoided simply by adding this line in your model:

attr_accessor :password_confirmation

If you want to handle the confirmation yourself, then just add:

validates_confirmation_of :password

If you dive into the code, you will find this in password.rb:

if require_password_confirmation
  validates_confirmation_of :password, validates_confirmation_of_password_field_options
  validates_length_of :password_confirmation, validates_length_of_password_confirmation_field_options
end
Swanand
That did it, thanks! Also for anyone else's benefit, adding: `validate_login_field false` to the authlogic configuration will prevent login id validation as well.
DJTripleThreat