Module: ActiveRecord::ActsAsAuthenticatable::ClassMethods
- Defined in:
- lib/active_record/acts_as_authenticatable.rb
Instance Method Summary collapse
-
#authenticate(username, password, remember = false) ⇒ Object
Authenticates the username and password.
-
#encrypt_password(password, password_seed) ⇒ Object
Encrypts the password using the given seed.
Instance Method Details
#authenticate(username, password, remember = false) ⇒ Object
Authenticates the username and password
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_record/acts_as_authenticatable.rb', line 22 def authenticate(username, password, remember = false) user=self.find_by_username username if user expected_password=encrypt_password(password, user.password_seed) unless expected_password == user.hashed_password && user.active user = nil else user.create_remember_me_token if remember end end return user end |
#encrypt_password(password, password_seed) ⇒ Object
Encrypts the password using the given seed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/active_record/acts_as_authenticatable.rb', line 36 def encrypt_password(password, password_seed) pass_to_hash=password + "Securasaurus" + password_seed case AUTHENTASAURUS[:hashing] when "SHA2" Digest::SHA2.hexdigest(pass_to_hash) when "SHA1" Digest::SHA1.hexdigest(pass_to_hash) when "MD5" Digest::MD5.hexdigest(pass_to_hash) else Digest::SHA2.hexdigest(pass_to_hash) end end |