java - 在我将密码输入我的 java 程序时如何阻止命令提示符显示我的密码

标签 java console password-protection

<分区>

所以我有这个应用程序,我从命令提示符读取用户输入,当用户输入他/她的密码时,我想隐藏它,这样其他人就看不到它了:

Please enter your password below
this is password

我想这样显示:

Please enter your password below
****************

那么有什么方法可以在 java 控制台应用程序中执行此操作吗?

最佳答案

看看 Console 类,它有 readPassword()

语法:

public char[] readPassword(String fmt,Object... args)

提供格式化的提示,然后在禁用回显的情况下从控制台读取密码或密码。

参数:

fmt - A format string as described in Format string syntax for the prompt text.

args - Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by the Java Virtual Machine Specification.

Returns - A character array containing the password or passphrase read from the console, not including any line-termination characters, or null if an end of stream has been reached.

关于java - 在我将密码输入我的 java 程序时如何阻止命令提示符显示我的密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20211619/

相关文章:

java - 管理/创建动态安全策略规则的最佳 Java 框架?

Node.js:将标准输出捕获到字符串变量中的最简单方法

Python - 使用 scrypt 存储密码的正确方法?

.htaccess - 使用.htaccess密码保护虚拟目录

Java 正则表达式 - 字母数字,最多一个连字符,句点或下划线,七个字符长

java - 类中的 Getter 模式?

c# - 如何从一个线程使用 Console.ReadLine 并从另一个线程使用 ConsoleKeys?

c# - 如何在具有 Windows 应用程序输出类型的 C# 程序上显示控制台

security - 暴力攻击排列

java - 简单的 Java 错误