0

I'm an ICT student and I need help. Our professor asked us to create a login system. I've already made one, but the problem is that the input is supposed to be hidden. How do I do that?

For example,

import java.util.Scanner;
int password;
Scanner x = new Scanner(System.in);
password = x.nextInt();

I need to hide the input, and turn that message into an asterisk '*'. Kinda how Facebook does it.

2 Answers2

0

See this solution

Namely:

Console console = System.console();

String enteredPassword = new String(console.readPassword("Please enter your password: "));
        
System.out.println("You entered: " + enteredPassword);
techied
  • 26
  • 1
-1

Good luck, with project.
So, I say put a check box that changes the value of some boolean variable, say, flag and the rest is something like this:

    String user_name;
    String pass;
    boolean flag;

    void checkBoxPropertyChanged(Action e) {
        flag =! flag;
        changePasswordField();
    }



    void changePasswordField() { 
        String hidden = ""; 
        int len = pass.length();

        for(int i = 0; i<len; i++) 
            hidden += "*"; 
        passwordField.setText((flag) ? pass : hidden); 
    }
Sakhund
  • 228
  • 1
  • 5
  • 32