diff --git a/hobo/hobo/lib/hobo/user.rb b/hobo/hobo/lib/hobo/user.rb index ac6f3c6..67e81f3 100644 --- a/hobo/hobo/lib/hobo/user.rb +++ b/hobo/hobo/lib/hobo/user.rb @@ -32,7 +32,7 @@ module Hobo end validates_confirmation_of :password, :if => :new_password_required? - password_validations + validate :validate_password validate :validate_current_password_when_changing_password # Virtual attributes for setting and changing the password @@ -55,12 +55,7 @@ module Hobo # Additional classmethods for authentication module ClassMethods - - # Validation of the plaintext password - def password_validations - validates_length_of :password, :within => 4..40, :if => :new_password_required? - end - + def login_attribute=(attr, validate=true) @login_attribute = attr = attr.to_sym unless attr == :login @@ -177,6 +172,11 @@ module Hobo changing_password? && !authenticated?(current_password) and errors.add :current_password, Hobo::Translations.ht("hobo.messages.current_password_is_not_correct", :default => "is not correct") end + # Validation of the plaintext password. Override this function + # to change your validation. + def validate_password + errors.add(:password, Hobo::Translations.ht("hobo.messages.validate_password", :default => "must be at least 6 characters long and must not consist solely of lowercase letters.")) if new_password_required? && (password.nil? || password.length<6 || /^[[:lower:]]*$/.match(password)) + end end end