Module: Authlogic::ActsAsAuthentic::Password::Methods

Defined in:
lib/authlogic/acts_as_authentic/password.rb

Overview

The methods related to the password field.

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/authlogic/acts_as_authentic/password.rb', line 225

def self.included(klass)
  return if klass.crypted_password_field.nil?
  
  klass.class_eval do
    include InstanceMethods
    
    if validate_password_field
      validates_length_of password_field, validates_length_of_password_field_options
      
      if require_password_confirmation
        validates_confirmation_of password_field, validates_confirmation_of_password_field_options
        validates_length_of "#{password_confirmation_field}", validates_length_of_password_confirmation_field_options
      end
    end
    
    after_save :reset_password_changed

    # The password
    define_method password_field do
      @password
    end

    # This is a virtual method. Once a password is passed to it, it will create new password salt as well as encrypt
    # the password.
    define_method "#{password_field}=" do |pass|
      return if ignore_blank_passwords? && pass.blank?
      before_password_set
      @password = pass
      
      arguments_type = nil
      if act_like_restful_authentication?
        arguments_type = :restful_authentication
      elsif salt_first?
        arguments_type = :salt_first
      end

      send("#{password_salt_field}=", Authlogic::Random.friendly_token) if password_salt_field
      send("#{crypted_password_field}=", crypto_provider.encrypt(*encrypt_arguments(@password, false, arguments_type)))
      @password_changed = true
      after_password_set
    end
  end
end