import java.util.
ArrayList;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class User {
private String firstName;
private String lastName;
private String uuid;
/** The MD5 hash of the user's pin number */
private byte pinHash[];
/** List of accounts for this user */
private ArrayList<Account> accounts;
/**
* Create a new user
* @param firstName the user's first Name
* @param lastName the user's last name
* @param pin the user's account pin number
* @param theBank the Bank object that the user
*/
public User(String firstName, String lastName, String pin, Bank theBank)
//set user's name
this.firstName = firstName;
this.lastName = lastName;
// store the pin's MD5 hash, rather than the original value, for
//security reason
try {
MessageDigest md = MessageDigest.getInstance("MD5");
this.pinHash = md.digest(pin.getBytes());
} catch (NoSuchAlgorithmException e) {
//TODO Auto-generated catch block
System.err.println("error, caught
NoSuchAlgorithmException");
e.printStackTrace();
System.exit(1);
//get a new, unique universal Id for the user
this.uuid = theBank.getNewUserUUID();
//create empty list of accounts
this.accounts = new ArrayList<Account>();
//print log message
System.out.printf("New User %s, %s with ID %s created .\n", lastName, firstName,
this.uuid);
/**
* Add an account for the user
* @param anAcct the account to add
*/
public void addAccount(Account anAcct) {
this.accounts.add(anAcct);
}
/**
* Return the user's UUID
* @return the uuid
*/
public String getUUID() {
/**
* Check whether a given pin matches the true User pin
*/
public boolean validatePin(String aPin) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");
return MessageDigest.isEqual(md.digest(aPin.getBytes()),
this.pinHash);
} catch (NoSuchAlgorithmException e) {
System.err.println("error, caught NoSuchAlgorithmException");
e.printStackTrace();
System.exit(1);
return false;