Module: WizAuthc::RealmModel::InstanceMethods
- Defined in:
- lib/wizdog/authc/realm_model.rb
Instance Method Summary collapse
-
#authenticate(credential = nil) ⇒ Object
attr_accessor :password, :password_confirmation.
-
#encrypt(password) ⇒ Object
Encrypts the password with the user salt.
- #encrypt_password ⇒ Object
Instance Method Details
#authenticate(credential = nil) ⇒ Object
attr_accessor :password, :password_confirmation
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/wizdog/authc/realm_model.rb', line 51 def authenticate(credential = nil) self.credential == encrypt(credential) # realm_map = self.class.get_realm_map # my_principal = realm_map[:principal] # my_credential = realm_map[:credential] # if self.respond_to?(my_principal) && self.respond_to?(my_credential) # if principal == self.send(my_principal) && credential == self.send(my_credential) # return self.send(my_principal) # end # end end |
#encrypt(password) ⇒ Object
Encrypts the password with the user salt
68 69 70 |
# File 'lib/wizdog/authc/realm_model.rb', line 68 def encrypt(password) Digest::SHA1.hexdigest("--#{salt}--#{password}--") end |
#encrypt_password ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/wizdog/authc/realm_model.rb', line 72 def encrypt_password if new_record? self.password = '123456' if self.password.blank? self.salt = Digest::SHA1.hexdigest("--#{Time.now.to_s}--#{login}--") self.password = encrypt(self.password) end end |