So I’m pretty new to the whole Java UI thing and I just came across a problem where the output of one of my if statements ( the ones with that suggest adding numbers, special chars etc., the password strength one is working just fine) just wouldn’t change no matter how many times I try to change the input in my text Field.
.
`if(e.getSource()==click){
pass = Input.getText();
Pattern upperCase = Pattern.compile("[A-Z]");
Pattern numbers = Pattern.compile("[0-9]");
Pattern special = Pattern.compile("[^A-Za-z0-9]");
Matcher upper = upperCase.matcher(pass);
Matcher number = numbers.matcher(pass);
Matcher spec = special.matcher(pass);
boolean a = upper.find();
boolean b = number.find();
boolean c = spec.find();
if(pass.length() > 15 || pass.length() < 5){
Text1.setText("The password must be between 5 and 15 characters");
}
else{
if (a && b && c) {
Text1.setText("The password looks strong");
} else {
if ((a && b) || (b && c) || (c && a)) {
Text1.setText("The password strength is average");
if(!a){
Text2a.setText("*Try adding some uppercase letters");
}
if(!b){
Text2b.setText("*Try adding some numbers");
}
if(!c){
Text2c.setText("*Try adding some special characters");
}
}
else {
Text1.setText("The password seems pretty weak");
if(!a){
Text2a.setText("*Try adding some uppercase letters");
}
if(!b){
Text2b.setText("*Try adding some numbers");
}
if(!c){
Text2c.setText("*Try adding some special characters");
}
}
}
}
}`
I tried rearranging the if statements in different ( and outside ) loops, using a separate method for all the code and calling it in the else statement, but nothing seems to be working.
I want for the “try adding blah blah” if statements to change according to the String input by the user but can’t figure it out.
Thanks!!
ImShadx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.