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

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#passwordObject

The password



349
350
351
352
# File 'lib/authlogic/acts_as_authentic/password.rb', line 349

def password
  return nil unless defined?(@password)
  @password
end

#password=(pass) ⇒ Object

This is a virtual method. Once a password is passed to it, it will create new password salt as well as encrypt the password.



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/authlogic/acts_as_authentic/password.rb', line 356

def password=(pass)
  return if ignore_blank_passwords? && pass.blank?
  before_password_set
  @password = pass
  if password_salt_field
    send("#{password_salt_field}=", Authlogic::Random.friendly_token)
  end
  encryptor_args_type = act_like_restful_authentication? ? :restful_authentication : nil
  send(
    "#{crypted_password_field}=",
    crypto_provider.encrypt(
      *encrypt_arguments(@password, false, encryptor_args_type)
    )
  )
  @password_changed = true
  after_password_set
end

#reset_passwordObject Also known as: randomize_password

Resets the password to a random friendly token.



408
409
410
411
412
# File 'lib/authlogic/acts_as_authentic/password.rb', line 408

def reset_password
  friendly_token = Authlogic::Random.friendly_token
  self.password = friendly_token
  self.password_confirmation = friendly_token if self.class.require_password_confirmation
end

#reset_password!Object Also known as: randomize_password!

Resets the password to a random friendly token and then saves the record.



416
417
418
419
# File 'lib/authlogic/acts_as_authentic/password.rb', line 416

def reset_password!
  reset_password
  save_without_session_maintenance(validate: false)
end

#valid_password?(attempted_password, check_against_database = check_passwords_against_database? ) ⇒ Boolean

Accepts a raw password to determine if it is the correct password.

  • attempted_password [String] - password entered by user

  • check_against_database [boolean] - Should we check the password against the value in the database or the value in the object? Default taken from config option check_passwords_against_database. See config method for more information.

Returns:

  • (Boolean)


381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'lib/authlogic/acts_as_authentic/password.rb', line 381

def valid_password?(
  attempted_password,
  check_against_database = check_passwords_against_database?
)
  crypted = crypted_password_to_validate_against(check_against_database)
  return false if attempted_password.blank? || crypted.blank?
  before_password_verification

  crypto_providers.each_with_index do |encryptor, index|
    next unless encryptor_matches?(
      crypted,
      encryptor,
      index,
      attempted_password,
      check_against_database
    )
    if transition_password?(index, encryptor, check_against_database)
      transition_password(attempted_password)
    end
    after_password_verification
    return true
  end

  false
end