Class: Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/quartz_flow/authentication.rb

Instance Method Summary collapse

Constructor Details

#initialize(password_file) ⇒ Authentication

Returns a new instance of Authentication.



18
19
20
21
22
# File 'lib/quartz_flow/authentication.rb', line 18

def initialize(password_file)
  @password_file = password_file
  @accounts = {}
  load_password_file(password_file)
end

Instance Method Details

#add_account(login, unhashed_password) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/quartz_flow/authentication.rb', line 24

def (, unhashed_password)
  if @accounts.has_key?
    raise "The account #{} already exists"
  end
  raise "Password cannot be empty" if unhashed_password.nil?
  (, unhashed_password)
end

#authenticate(login, password) ⇒ Object

Returns true on success, false if the user cannot be authenticated



40
41
42
43
44
45
46
# File 'lib/quartz_flow/authentication.rb', line 40

def authenticate(, password)
  # Reload the password file in case users were added/deleted
  acct = @accounts[]
  return false if ! acct
  hashed = hash_password(password, acct.salt)
  hashed == acct.password_hash
end

#del_account(login) ⇒ Object



32
33
34
35
36
37
# File 'lib/quartz_flow/authentication.rb', line 32

def ()
  if ! @accounts.has_key?()
    raise "The account #{} does not exist"
  end
  ()
end