Module: Authlogic::ActsAsAuthentic::Password::Methods::InstanceMethods
- Defined in:
- lib/authlogic/acts_as_authentic/password.rb
Instance Method Summary collapse
-
#password ⇒ Object
The password.
-
#password=(pass) ⇒ Object
This is a virtual method.
-
#reset_password ⇒ Object
(also: #randomize_password)
Resets the password to a random friendly token.
-
#reset_password! ⇒ Object
(also: #randomize_password!)
Resets the password to a random friendly token and then saves the record.
-
#valid_password?(attempted_password) ⇒ Boolean
Accepts a raw password to determine if it is the correct password or not.
Instance Method Details
#password ⇒ Object
The password
155 156 157 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 155 def 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.
161 162 163 164 165 166 167 168 169 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 161 def password=(pass) return if ignore_blank_passwords? && pass.blank? before_password_set @password = pass send("#{password_salt_field}=", Authlogic::Random.friendly_token) if password_salt_field send("#{crypted_password_field}=", crypto_provider.encrypt(*encrypt_arguments(@password, act_like_restful_authentication? ? :restful_authentication : nil))) @password_changed = true after_password_set end |
#reset_password ⇒ Object Also known as: randomize_password
Resets the password to a random friendly token.
203 204 205 206 207 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 203 def reset_password friendly_token = Authlogic::Random.friendly_token self.password = friendly_token self.password_confirmation = friendly_token end |
#reset_password! ⇒ Object Also known as: randomize_password!
Resets the password to a random friendly token and then saves the record.
211 212 213 214 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 211 def reset_password! reset_password save_without_session_maintenance(false) end |
#valid_password?(attempted_password) ⇒ Boolean
Accepts a raw password to determine if it is the correct password or not.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/authlogic/acts_as_authentic/password.rb', line 172 def valid_password?(attempted_password) return false if attempted_password.blank? || send(crypted_password_field).blank? before_password_verification crypto_providers = [crypto_provider] + transition_from_crypto_providers crypto_providers.each_with_index do |encryptor, index| # The arguments_type of for the transitioning from restful_authentication arguments_type = (act_like_restful_authentication? && index == 0) || (transition_from_restful_authentication? && index > 0 && encryptor == Authlogic::CryptoProviders::Sha1) ? :restful_authentication : nil if encryptor.matches?(send(crypted_password_field), *encrypt_arguments(attempted_password, arguments_type)) # If we are transitioning from an older encryption algorithm and the password is still using the old algorithm # then let's reset the password using the new algorithm. If the algorithm has a cost (BCrypt) and the cost has changed, update the password with # the new cost. if index > 0 || (encryptor.respond_to?(:cost_matches?) && !encryptor.cost_matches?(send(crypted_password_field))) self.password = attempted_password save(false) end after_password_verification return true end end false end |