Hello everyone!
I am currently working on a login code,i've put it in another program and the login is operational.But the thing is when i type in a wrong password,i get a message that tells me invalid password but logs in instead of making me try again, I've tried to put a do while loop with it but ending up with errors.
Can anyone help me? here is the code MyLogin in the username and password constructor that i call i n this one!
private boolean login() {
boolean userValid = false;
MyLogin Login = new MyLogin (new Frame("")); //Referencing MyLogin
requestFocus();
if (Login.id) {
username = Login.username.getText();
password = Login.password.getText();
userValid = validateUser(username , password);
// System.out.println
//("The password for " + username
// + " is " + (userValid?"valid":"invalid"));
JOptionPane.showMessageDialog(new JFrame(), "The password is invalid for " + username );
}
else
System.out.println
("Cancel was pressed.");
Login.dispose();
return userValid;
}
private boolean validateUser(
String usr, String pwd) {
username = "Olliver";
password = "Lim";
return (usr.equals(username) && pwd.equals(password));
}
********************************************************
Here is what I have been trying to do
//start login method
private boolean login() {
do{
boolean userValid = false;
MyLogin Login = new MyLogin (new Frame("")); //Referencing MyLogin
requestFocus();
if (Login.id) {
username = Login.username.getText();
password = Login.password.getText();
userValid = validateUser(username , password);
// System.out.println
//("The password for " + username
// + " is " + (userValid?"valid":"invalid"));
JOptionPane.showMessageDialog(new JFrame(), "The password is invalid for " + username );
}
else
System.out.println
("Cancel was pressed.");
Login.dispose();
//return userValid;
}while( equals(username)&& equals(password));
return isValid();
}
private boolean validateUser(String usr, String pwd) {
username = "Olliver";
password = "Lim";
return (usr.equals(username) && pwd.equals(password));
}
Hope someone can help me!!
[ October 29, 2007: Message edited by: Olliver Lim Kam Sian ]