Advertisement
heavenriver

InMemoryLogin.java (path: ../login/impl)

May 26th, 2012
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. /**
  2.   * Implements the Login interface. Defines a list-based set of accounts.
  3.   */
  4.  
  5. package login.impl;
  6. import login.*;
  7. import java.util.*;
  8.  
  9. public class InMemoryLogin implements Login
  10.     {
  11.    
  12.     public ArrayList<Account> account;
  13.    
  14.     /**
  15.       * Adds a given person's login credentials to the list.
  16.       * @param login The username associated to the account.
  17.       * @param password The password associated to the account.
  18.       * @param email The email associated to the account.
  19.       */
  20.    
  21.     public void add(String login, String password, String email)
  22.         {
  23.         if(account == null)
  24.             account = new ArrayList<Account>();
  25.         Account a = new Account(login, password, email);
  26.         account.add(a);
  27.         }
  28.    
  29.     /**
  30.       * Checks the presence of a given account in the list. Returns it if present.
  31.       * @param login The username associated to the account.
  32.       * @param password The password associated to the account.
  33.       * @return The account associated to the given access credentials, if present.
  34.       */
  35.    
  36.     public Account login(String login, String password)
  37.         {
  38.         if(account == null)
  39.             return null;
  40.         for(int i = 0; i < account.size(); i++)
  41.             {
  42.             if(account.get(i).getLogin().equals(login) && account.get(i).getPassword().equals(password))
  43.                 return account.get(i);
  44.             }
  45.         return null;
  46.         }
  47.    
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement