I'm doing a password check which has to comply with certain points. There's two text fields for password confirmation and for some reason, when both passwords comply with everything and are the same, it goes into "Passwords don't match" even though they do and I can't figure out why! Help appreciated.
public boolean passwordCheck(String password1, String password2) {
boolean valid = false;
do {
if(password1.length()>20) {
errorLabel.setText("* Password is too long");
System.out.println("Password is too long");
valid = false;
break;
} else if (password1.length()<4) {
errorLabel.setText("* Password is too short");
System.out.println("Password is too short");
valid = false;
break;
} else if (password1 != password2) {
System.out.println(password1 + "==" + password2);
errorLabel.setText("* Passwords do not match!");
System.out.println("Password do not match!");
valid = false;
break;
} else if (password1 == password2){
valid = true;
}
} while (!valid);
System.out.println("outside the loop" + valid);
return valid;
}