Module: Minimalist::Authentication::ClassMethods

Defined in:
lib/minimalist/authentication.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(email, password) ⇒ Object



36
37
38
39
40
41
# File 'lib/minimalist/authentication.rb', line 36

def authenticate(email, password)
  return if email.blank? || password.blank?
  user = active.first(:conditions => {:email => email})
  return unless user && user.authenticated?(password)
  return user
end

#guestObject



56
57
58
59
60
# File 'lib/minimalist/authentication.rb', line 56

def guest
  new.tap do |user|
    user.email = GUEST_USER_EMAIL
  end
end

#make_tokenObject



52
53
54
# File 'lib/minimalist/authentication.rb', line 52

def make_token
  BCrypt::Engine.generate_salt(CALIBRATED_BCRYPT_COST)
end

#secure_digest(string, salt, version = 1) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/minimalist/authentication.rb', line 43

def secure_digest(string, salt, version = 1)
  case version
    when 0 then Digest::MD5.hexdigest(string.to_s)
    when 1 then Digest::SHA1.hexdigest("#{string}--#{salt}")
    when 2 then Digest::SHA2.hexdigest("#{string}#{salt}", 512)
    when 3 then BCrypt::Password.new(BCrypt::Engine.hash_secret(string, salt)).checksum
  end
end