How to mask a password in Java 5?(如何在 Java 5 中屏蔽密码?)
问题描述
我正在尝试在 Java 中屏蔽密码.Sun java 提出了一种屏蔽密码的方法,如下所示.
I am trying to mask a password in Java. Sun java has suggested a way to mask a password as follows.
隐藏密码
它使用一种简单的方法来做到这一点.
It uses a simple way to do that.
public void run () {
stop = true;
while (stop) {
System.out.print(" 10*");
try {
Thread.currentThread().sleep(1);
} catch(InterruptedException ie) {
ie.printStackTrace();
}
}
}
但是这种方法有几个缺点.
But this approach has several drawbacks.
如果用户使用箭头键 + 删除键,密码就会被泄露.
If the user uses the arrow keys + delete keys the password gets revealed.
如果用户不小心同时按下了 2 个键(打字速度极快),某些字符不会被屏蔽.
If the user accidentally press 2 keys at the same time (Extremely high typing speed) some characters does not get masked.
你们有什么方法可以得到 100% 正确的遮罩吗?
Do you guys think of any way that can get a 100% correct masking?
推荐答案
使用Console.readPassword().
这篇关于如何在 Java 5 中屏蔽密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Java 5 中屏蔽密码?


基础教程推荐
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01