0

I have a question for you; In Java, Is there a way of display or show in the console asterisks **** instead of the password. Thank you very much, in advance.

import java.util.Scanner;

public class ClasePrincipal {

    public static void main(String[] args) {

        String Username1,Username2;
        String Password1,Password2;

        Password1 = "123456";
        Username1 = "Michael";
        
        Password2 = "123456";
        Username2 = "Tony";

        int contador = 1;
        while (contador <= 3) {
            try {
                Scanner input1 = new Scanner(System.in);
                System.out.println("Enter username : ");
                String username = input1.next();

                Scanner input2 = new Scanner(System.in);
                System.out.println("Enter Password : ");
                String password = input2.next();

                if ((username.equals(Username1) && (password.equals(Password1))) || 
                        (username.equals(Username2) && (password.equals(Password2))))
                        {
                    System.out.println("Welcome!");
        //              ClasePadre_Abstracta mensajero = new ClaseHija_Consulta();
        //              mensajero.setSaldo(0);
        //              mensajero.Operaciones();
                    break;
                } else {
                    System.out.println("Wrong Password!");
                    contador++;
                }
            } catch (Exception e) {
                System.out.println("Block Account");
                return;
            }
        }
    }
}
Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
  • See this question: https://stackoverflow.com/questions/10819469/hide-input-on-command-line – Johan Nordlinder Apr 03 '22 at 19:18
  • I really appreciate, but I tried, and it doesn't work – Jose Quenta Apr 03 '22 at 19:21
  • @josequenta If that answer doesn't work for you, the thing you're typing in doesn't support it, and therefore what you want is not possible in the console. You could make a user interface with awt, swing, or javafx instead. – rzwitserloot Apr 03 '22 at 19:24

0 Answers0