usflix
Class UserDatabase
java.lang.Object
usflix.UserDatabase
public class UserDatabase
- extends java.lang.Object
UserDatabase class manages user database, and provides user account related methods.
- Version:
- 4.0 April 3, 2013.
- Author:
- EJ Jung
Field Summary |
static int |
minPwdLength
constant: minimum password length. |
private java.util.HashMap<java.lang.String,User> |
userDB
user database using HashMap. |
Method Summary |
User |
createAccount(java.lang.String f,
java.lang.String l,
java.lang.String u,
java.lang.String p)
This method checks if the password contains the username,
if the password length is less than the minPwdLength,
if username is unique, and if any of these conditions is true,
returns null. |
boolean |
isAvailable(java.lang.String u)
|
User |
login(java.lang.String u,
java.lang.String p)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
minPwdLength
public static final int minPwdLength
- constant: minimum password length. Currently 6.
- See Also:
- Constant Field Values
userDB
private java.util.HashMap<java.lang.String,User> userDB
- user database using HashMap.
UserDatabase
public UserDatabase()
createAccount
public User createAccount(java.lang.String f,
java.lang.String l,
java.lang.String u,
java.lang.String p)
- This method checks if the password contains the username,
if the password length is less than the minPwdLength,
if username is unique, and if any of these conditions is true,
returns null. If the provided parameters pass all these checks,
this method creates a new User objects with the provided parameters,
adds it to the user database, and returns the newly created User object.
- Parameters:
f
- first namel
- last nameu
- usernamep
- password
- Returns:
- User object created with the parameter, if successful. Otherwise null
login
public User login(java.lang.String u,
java.lang.String p)
- Parameters:
u
- usernamep
- password
- Returns:
- If the user exists in the database and the password matches,
then return the User object. Otherwise null.
isAvailable
public boolean isAvailable(java.lang.String u)
- Parameters:
u
-
- Returns:
- true if this username is available, false otherwise.