Module: Authlogic::ActsAsAuthentic::Password::Config
- Defined in:
- lib/authlogic/acts_as_authentic/password.rb
Overview
All configuration for the password aspect of acts_as_authentic.
Instance Method Summary collapse
-
#check_passwords_against_database(value = nil) ⇒ Object
(also: #check_passwords_against_database=)
When calling valid_password?(“some pass”) do you want to check that password against what’s in that object or whats in the database.
-
#crypted_password_field(value = nil) ⇒ Object
(also: #crypted_password_field=)
The name of the crypted_password field in the database.
-
#crypto_provider(value = nil) ⇒ Object
(also: #crypto_provider=)
The class you want to use to encrypt and verify your encrypted passwords.
-
#ignore_blank_passwords(value = nil) ⇒ Object
(also: #ignore_blank_passwords=)
By default passwords are required when a record is new or the crypted_password is blank, but if both of these things are met a password is not required.
-
#merge_validates_confirmation_of_password_field_options(options = {}) ⇒ Object
See merge_validates_length_of_password_field_options.
-
#merge_validates_length_of_password_confirmation_field_options(options = {}) ⇒ Object
See merge_validates_length_of_password_field_options.
-
#merge_validates_length_of_password_field_options(options = {}) ⇒ Object
A convenience function to merge options into the validates_length_of_login_field_options.
-
#password_salt_field(value = nil) ⇒ Object
(also: #password_salt_field=)
The name of the password_salt field in the database.
-
#require_password_confirmation(value = nil) ⇒ Object
(also: #require_password_confirmation=)
Whether or not to require a password confirmation.
-
#transition_from_crypto_providers(value = nil) ⇒ Object
(also: #transition_from_crypto_providers=)
Let’s say you originally encrypted your passwords with Sha1.
-
#validate_password_field(value = nil) ⇒ Object
(also: #validate_password_field=)
Whether or not to validate the password field.
-
#validates_confirmation_of_password_field_options(value = nil) ⇒ Object
(also: #validates_confirmation_of_password_field_options=)
A hash of options for the validates_confirmation_of call for the password field.
-
#validates_length_of_password_confirmation_field_options(value = nil) ⇒ Object
(also: #validates_length_of_password_confirmation_field_options=)
A hash of options for the validates_length_of call for the password_confirmation field.
-
#validates_length_of_password_field_options(value = nil) ⇒ Object
(also: #validates_length_of_password_field_options=)
A hash of options for the validates_length_of call for the password field.
Instance Method Details
#check_passwords_against_database(value = nil) ⇒ Object Also known as: check_passwords_against_database=
When calling valid_password?(“some pass”) do you want to check that password against what’s in that object or whats in the database. Take this example:
u = User.first
u.password = "new pass"
u.valid_password?("old pass")
Should the last line above return true or false? The record hasn’t been saved yet, so most would assume true. Other would assume false. So I let you decide by giving you this option.
-
Default:
true -
Accepts:
Boolean
91 92 93 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 91 def check_passwords_against_database(value = nil) rw_config(:check_passwords_against_database, value, true) end |
#crypted_password_field(value = nil) ⇒ Object Also known as: crypted_password_field=
The name of the crypted_password field in the database.
-
Default:
:crypted_password, :encrypted_password, :password_hash, or :pw_hash -
Accepts:
Symbol
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 21 def crypted_password_field(value = nil) rw_config( :crypted_password_field, value, first_column_to_exist( nil, :crypted_password, :encrypted_password, :password_hash, :pw_hash ) ) end |
#crypto_provider(value = nil) ⇒ Object Also known as: crypto_provider=
The class you want to use to encrypt and verify your encrypted passwords. See the Authlogic::CryptoProviders module for more info on the available methods and how to create your own.
-
Default:
CryptoProviders::SCrypt -
Accepts:
Class
204 205 206 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 204 def crypto_provider(value = nil) rw_config(:crypto_provider, value, CryptoProviders::SCrypt) end |
#ignore_blank_passwords(value = nil) ⇒ Object Also known as: ignore_blank_passwords=
By default passwords are required when a record is new or the crypted_password is blank, but if both of these things are met a password is not required. In this case, blank passwords are ignored.
Think about a profile page, where the user can edit all of their information, including changing their password. If they do not want to change their password they just leave the fields blank. This will try to set the password to a blank value, in which case is incorrect behavior. As such, Authlogic ignores this. But let’s say you have a completely separate page for resetting passwords, you might not want to ignore blank passwords. If this is the case for you, then just set this value to false.
-
Default:
true -
Accepts:
Boolean
73 74 75 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 73 def ignore_blank_passwords(value = nil) rw_config(:ignore_blank_passwords, value, true) end |
#merge_validates_confirmation_of_password_field_options(options = {}) ⇒ Object
See merge_validates_length_of_password_field_options. The same thing, except for validates_confirmation_of_password_field_options
164 165 166 167 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 164 def ( = {}) self. = .merge() end |
#merge_validates_length_of_password_confirmation_field_options(options = {}) ⇒ Object
See merge_validates_length_of_password_field_options. The same thing, except for validates_length_of_password_confirmation_field_options
193 194 195 196 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 193 def ( = {}) self. = .merge() end |
#merge_validates_length_of_password_field_options(options = {}) ⇒ Object
A convenience function to merge options into the validates_length_of_login_field_options. So instead of:
self. =
.merge(:my_option => my_value)
You can do this:
:my_option => my_value
137 138 139 140 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 137 def ( = {}) self. = .merge() end |
#password_salt_field(value = nil) ⇒ Object Also known as: password_salt_field=
The name of the password_salt field in the database.
-
Default:
:password_salt, :pw_salt, :salt, nil if none exist -
Accepts:
Symbol
40 41 42 43 44 45 46 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 40 def password_salt_field(value = nil) rw_config( :password_salt_field, value, first_column_to_exist(nil, :password_salt, :pw_salt, :salt) ) end |
#require_password_confirmation(value = nil) ⇒ Object Also known as: require_password_confirmation=
Whether or not to require a password confirmation. If you don’t want your users to confirm their password just set this to false.
-
Default:
true -
Accepts:
Boolean
54 55 56 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 54 def require_password_confirmation(value = nil) rw_config(:require_password_confirmation, value, true) end |
#transition_from_crypto_providers(value = nil) ⇒ Object Also known as: transition_from_crypto_providers=
Let’s say you originally encrypted your passwords with Sha1. Sha1 is starting to join the party with MD5 and you want to switch to something stronger. No problem, just specify your new and improved algorithm with the crypt_provider option and then let Authlogic know you are transitioning from Sha1 using this option. Authlogic will take care of everything, including transitioning your users to the new algorithm. The next time a user logs in, they will be granted access using the old algorithm and their password will be resaved with the new algorithm. All new users will obviously use the new algorithm as well.
Lastly, if you want to transition again, you can pass an array of crypto providers. So you can transition from as many algorithms as you want.
-
Default:
nil -
Accepts:
Class or Array
226 227 228 229 230 231 232 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 226 def transition_from_crypto_providers(value = nil) rw_config( :transition_from_crypto_providers, (!value.nil? && [value].flatten.compact) || value, [] ) end |
#validate_password_field(value = nil) ⇒ Object Also known as: validate_password_field=
Whether or not to validate the password field.
-
Default:
true -
Accepts:
Boolean
100 101 102 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 100 def validate_password_field(value = nil) rw_config(:validate_password_field, value, true) end |
#validates_confirmation_of_password_field_options(value = nil) ⇒ Object Also known as: validates_confirmation_of_password_field_options=
A hash of options for the validates_confirmation_of call for the password field. Allows you to change this however you want.
**Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or merge options into it. Checkout the convenience function merge_validates_length_of_password_field_options to merge options.**
-
Default:
=> :require_password? -
Accepts:
Hash of options accepted by validates_confirmation_of
152 153 154 155 156 157 158 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 152 def (value = nil) rw_config( :validates_confirmation_of_password_field_options, value, if: :require_password? ) end |
#validates_length_of_password_confirmation_field_options(value = nil) ⇒ Object Also known as: validates_length_of_password_confirmation_field_options=
A hash of options for the validates_length_of call for the password_confirmation field. Allows you to change this however you want.
Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or merge options into it. Checkout the convenience function merge_validates_length_of_password_field_options to merge options.
-
Default:
validates_length_of_password_field_options -
Accepts:
Hash of options accepted by validates_length_of
179 180 181 182 183 184 185 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 179 def (value = nil) rw_config( :validates_length_of_password_confirmation_field_options, value, ) end |
#validates_length_of_password_field_options(value = nil) ⇒ Object Also known as: validates_length_of_password_field_options=
A hash of options for the validates_length_of call for the password field. Allows you to change this however you want.
**Keep in mind this is ruby. I wanted to keep this as flexible as possible, so you can completely replace the hash or merge options into it. Checkout the convenience function merge_validates_length_of_password_field_options to merge options.**
-
Default:
=> 8, :if => :require_password? -
Accepts:
Hash of options accepted by validates_length_of
115 116 117 118 119 120 121 122 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 115 def (value = nil) rw_config( :validates_length_of_password_field_options, value, minimum: 8, if: :require_password? ) end |