Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Java login using a hashmap

807606Mar 26 2007 — edited Mar 26 2007
I am trying to code a login function using java, i am using a hashmap to do this. Here is my code so far i am stuck, i am at a point where i can't get the program to check the username. Ideally i would like the program to check if the username is in the hashmap and then ask for the password to be entered and then the user can check their current balance.

// Connect the input and the output to and from the socket
PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
String inputLine, outputLine = null;
HashMap UserPass = new HashMap();
HashMap Balance = new HashMap();
String username = null;
UserPass.put ("Dave", "123");
UserPass.put ("Tom", "456");
UserPass.put ("Joe", "789");
Balance.put ("Dave", "1000");
Balance.put ("Tom", "-100");
Balance.put ("Joe", "50");
// Repeatedly loop getting input from the client
// check it with the state object for the response
// and send it to the client until the client
// says Bye.

while ((inputLine = in.readLine()) != null) {
String[] splitInput = inputLine.split(" ");

if (splitInput[0].equals("login"))
{

if (splitInput[1].equals(""))
// Lookup user in hashmap


} else if (splitInput[0].equals("password") && username != null)
{

} else
{

}


//
// out.println(splitInput[0] + ", " + splitInput[1]);

if (outputLine.equals("Bye."))

break;
}
// Tidy up
out.close();
in.close();
clientSocket.close();
serverSocket.close();
}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 23 2007
Added on Mar 26 2007
4 comments
2,387 views