Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Implements the Login interface. Defines a file-based set of accounts.
- */
- package login.impl;
- import login.*;
- import java.io.*;
- public class PersistentLogin implements Login
- {
- public File file;
- /**
- * Initializes the file to a given value.
- * @param f The given file.
- */
- public PersistentLogin(File f)
- {
- file = f;
- }
- /**
- * Checks the presence of a given account in the file. Returns it if present. No exceptions thrown; returns null where an IOException would be present.
- * @param login The username associated to the account.
- * @param password The password associated to the account.
- * @return The account associated to the given access credentials, if present.
- */
- public Account login(String login, String password)
- {
- try
- {
- FileReader f = new FileReader(file);
- BufferedReader br = new BufferedReader(f);
- String line = br.readLine();
- while(line != null)
- {
- if(!(line.equals("")))
- {
- String[] data = line.split(";");
- if(data[0].equals(login) && data[1].equals(password))
- return new Account(data[0], data[1], data[2]);
- }
- line = br.readLine();
- }
- }
- catch(IOException e)
- {
- return null;
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement