I have a logic error that is giving me headaches, I need to make a login
system, the fields are burned, but I need to pass it to a method, when I execute it it does not return me true
or false
, and executing it as a method does not realize the count of the three attempts .
How could I improve it?
public class Login1 {
public static boolean login(boolean login) {
Scanner teclado = new Scanner(System.in);
int cont;
boolean salir = false;
String user[] = {"Usuario1", "Usuario2", "Usuario3"};
String usuario, contra;
String pass[] = {"uno1", "Dos2", "tRes3"};
System.out.println("Ingrese su usuario y contraseña para iniciar");
while (!salir) {
for (int i = 0; i < user.length; i++) {
int contInt = 1;
int a = i;
System.out.println("3[30mIntento " + (a + 1));
System.out.println("Digite su usuario: ");
usuario = teclado.nextLine();
System.out.println("Digite su contraseña: ");
contra = teclado.nextLine();
if (usuario.equals(user[0]) && (contra.equals(pass[0])) || usuario.equals(user[1]) && (contra.equals(pass[1])) || usuario.equals(user[2]) && (contra.equals(pass[2]))) {
System.out.println("Bienvenido al sistema");
login=true;
salir = true;
//contInt++;
} else {
System.out.println(" ");
System.out.println("3[31m***********************************");
System.out.println("3[31m* USUARIO O CONTRASEÑA INCORRECTA *");
System.out.println("3[31m***********************************");
System.out.println(" ");
if (i == 2) {
System.err.println("HA CUMPLIDO CON LA CANTIDAD DE INTENTOS PERMITIDOS.");
System.err.println("SISTEMA BLOQUEADO, ESPERE... ");
System.out.println(" ");
try {
Thread.sleep(10000); // espera en milisegundos
} catch (Exception e) {
login=false;
}
}
salir = false;
}
}
}//fin wh
return login;
}
public static void main(String[] args) {
boolean iniciar = true;
Login1.login(iniciar);
System.out.println(login(iniciar));
}
}