Module: Authentasaurus::Ar::ActsAsAuthenticatable::ClassMethods
- Defined in:
- lib/authentasaurus/ar/acts_as_authenticatable.rb
Instance Method Summary collapse
-
#authenticate(username_or_email, password, remember = false) ⇒ Object
Authenticates the username (or email) and password.
-
#encrypt_password(password, password_seed) ⇒ Object
Encrypts the password using the given seed.
Instance Method Details
#authenticate(username_or_email, password, remember = false) ⇒ Object
Authenticates the username (or email) and password
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/authentasaurus/ar/acts_as_authenticatable.rb', line 23 def authenticate(username_or_email, password, remember = false) user=self.find_by_username(username_or_email) || self.find_by_email(username_or_email) 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
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/authentasaurus/ar/acts_as_authenticatable.rb', line 37 def encrypt_password(password, password_seed) pass_to_hash=password + "Securasaurus" + password_seed case Rails.application.config.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 |