我的密码程序可以隐藏键盘输入。当我输入密码时它是不可见的。
但我的问题是如何将密码输入显示为星号(*)
有人能帮帮我吗?:p
我的代码在这里:
public void login()
{
Scanner input = new Scanner(System.in);//create Scanner object
System.out.println("\n");
Console console = System.console();
char[] ad_password = "admin".toCharArray();
char[] sm_password = "salesman".toCharArray();
char[] passwordEntered = console.readPassword("Enter Password To Access The Project ( As Admin / Sales Man ): ");
if (Arrays.equals(ad_password, passwordEntered))
{
System.out.println("\n Congratulation!!! Access granted \n");
System.out.println("\n Welcome Admin. :-) \n\n");
Shoping_mall obj_ad_dis=new Shoping_mall();
obj_ad_dis.ad_dis();
}
else if(Arrays.equals(sm_password, passwordEntered))
{
System.out.println("\n Congratulation!!! Access granted \n");
System.out.println("\n Welcome Sales Man. :-) \n\n");
Shoping_mall obj1_sm_dis=new Shoping_mall();
obj1_sm_dis.sm_dis();
}
else
{
System.out.println("\n Error: Your Password Doesn't Meet. Access Denied !!! :-( \n\n");
System.out.println("\n Enter Correct Password.\n\n");
Shoping_mall obj_login=new Shoping_mall();//creat object for calling Admin_works() method
obj_login.login();
}
}