字符串到星号,屏蔽密码 [英] String to asterisk, masking password
问题描述
我正在为ATM机创建此简单的登录代码.输入用户名和密码,然后登录,效果很好.由于我没有连接到数据库或外部文本文件,而且我只有1个用户,因此它只是用Java代码编写的.但是,当您输入密码"p4ss"时,我希望它被屏蔽,因此与其在输入时不显示在屏幕上,不如在屏幕上看到"* * * *"或"(就像在Linux上输入pass一样).
I'm creating this simple login code for an ATM machine. You enter username and password and you logs in, that works just great. Since I'm not connecting to a database or an external text file and I've just got 1 user, it's just written plainly in the Java code. But when you enter the password "p4ss" I want it to be masked, so instead of seing it on the screen while typing you should see "* * * *" or " " just blank (Like when you enter pass on Linux).
当前我的代码如下:
String user;
String pass;
System.out.print("User: ");
user = Keyboard.readString();
System.out.print("Pass: ");
pass = Keyboard.readString();
if ((user.equals("Admin")) && (pass.equals("p4ss")))
{
menu();
}
else
{
out.println("Wrong username or password.");
}
非常感谢我能提供的帮助.
Would appreciate any help I could get.
推荐答案
Michael,看看Sun网站上的描述: https://web.archive.org/web/20120214061606/http://java.sun.com/developer/technicalArticles/Security/pwordmask
Michael, have a look at the description on Sun's website: https://web.archive.org/web/20120214061606/http://java.sun.com/developer/technicalArticles/Security/pwordmask
或者,如果您使用的是Java 5或更高版本,则可以使用以下命令:如何在Java 5中屏蔽密码?
Or, if you're using Java 5 or newer, you can use this: How to mask a password in Java 5?
这篇关于字符串到星号,屏蔽密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!