Does it have to be regular expression? I ask this because determining that using regular expression is necessary seems to me to be a case of XY problem.
If the use of regular expressions is not mandatory, you can do this:
public static boolean senhaForte(String senha) {
if (senha.length() < 6) return false;
boolean achouNumero = false;
boolean achouMaiuscula = false;
boolean achouMinuscula = false;
boolean achouSimbolo = false;
for (char c : senha.toCharArray()) {
if (c >= '0' && c <= '9') {
achouNumero = true;
} else if (c >= 'A' && c <= 'Z') {
achouMaiuscula = true;
} else if (c >= 'a' && c <= 'z') {
achouMinuscula = true;
} else {
achouSimbolo = true;
}
}
return achouNumero && achouMaiuscula && achouMinuscula && achouSimbolo;
}
And that still has the advantage that if you need to change the criteria of what is considered a strong password, it’s much easier to move it than in a regular expression.
Thank you very much friend, it was very valuable your help, the code ran beautiful :D Really, this way I do not need to use regular expressions to validate, much easier the understanding.
– Higor Vieira