Module: Cms::Authentication::Model::ClassMethods

Defined in:
lib/cms/authentication/model.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(login, password) ⇒ Object



20
21
22
23
# File 'lib/cms/authentication/model.rb', line 20

def authenticate(, password)
  u = () # need to get the salt
  u && u.authenticated?(password) && !u.expired? ? u : nil
end

#change_password(login, new_password) ⇒ Object

Method to make it easy to change a user’s password from the console, not used in the app



26
27
28
# File 'lib/cms/authentication/model.rb', line 26

def change_password(, new_password)
  ().change_password(new_password)
end

#make_tokenObject



30
31
32
# File 'lib/cms/authentication/model.rb', line 30

def make_token
  secure_digest(Time.now, (1..10).map{ rand.to_s })
end

#password_digest(password, salt) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/cms/authentication/model.rb', line 34

def password_digest(password, salt)
  key = '8771d0d9bef6f1091b723d2e701a17c811d69b26'
  digest = key
  10.times do
    digest = secure_digest(digest, salt, password, key)
  end
  digest
end

#secure_digest(*args) ⇒ Object



43
44
45
# File 'lib/cms/authentication/model.rb', line 43

def secure_digest(*args)
  Digest::SHA1.hexdigest(args.flatten.join('--'))
end