I'm building a login system in Java and I'm trying to mask the password input due to security measures but can't seem to find a way around it. This is what I'm Trying to do:
Username: User1
Password:******
Here's my code to give you an idea
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner Input = new Scanner (System.in);
System.out.println("Username:");
String Username = Input.nextLine();
System.out.println("Password:");
String Password = Input.nextLine();
}
}
Try readPassword() method of java It doesn't mask a * but it hide the input we type to console
cnsl = System.console();
char[] pwd = cnsl.readPassword("Password: ");
System.out.println("Password is: "+pwd);
like this.......
您可以使用https://docs.oracle.com/javase/7/docs/api/java/io/Console.html 中的Console.readPassword()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.