Class: Authentication
- Inherits:
-
Object
- Object
- Authentication
- Defined in:
- lib/quartz_flow/authentication.rb
Instance Method Summary collapse
- #add_account(login, unhashed_password) ⇒ Object
-
#authenticate(login, password) ⇒ Object
Returns true on success, false if the user cannot be authenticated.
- #del_account(login) ⇒ Object
-
#initialize(password_file) ⇒ Authentication
constructor
A new instance of Authentication.
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 add_account(login, unhashed_password) if @accounts.has_key?login raise "The account #{login} already exists" end raise "Password cannot be empty" if unhashed_password.nil? add_account_internal(login, 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(login, password) # Reload the password file in case users were added/deleted acct = @accounts[login] 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 del_account(login) if ! @accounts.has_key?(login) raise "The account #{login} does not exist" end del_account_internal(login) end |