The password must mayor o igual a 10 caracteres
contain letras
, números
and SIMBOLOS
, I need help because I have not been able to make the program detect the symbols to make it secure.
import java.util.Scanner;
public class clavejsjs {
public static void main(String[] args) {
Scanner clave = new Scanner(System.in);
String Contraseña;
System.out.println("Ingrese una contraseña:");
Contraseña = clave.next();
if (si_sirve(Contraseña))
System.out.println("La contraseña ingresada es segura.");
else
System.out.println("La contraseña ingresada no es segura.");
}
static boolean si_sirve(String Contraseña) {
if (Contraseña.length() >= 10) {
boolean numero = false;
boolean letra = false;
char Pas;
for(int i=0; i<Contraseña.length(); i++) {
Pas = Contraseña.charAt(i);
if (Character.isDigit(Pas))
numero = true;
if(Character.isLetter(Pas))
letra = true;
}
if (numero && letra)
return true;
else
return false;
} else {
return false;
}
}
}
You have to establish a criteria to determine when a character is a symbol or not.
As they commented, you can say that if it is not a letter or a digit, it is a character. Yes No No.
Adding that and rewriting the code to improve its readability, you get the following: