本文整理汇总了Java中java.io.Console.readPassword方法的典型用法代码示例。如果您正苦于以下问题:Java Console.readPassword方法的具体用法?Java Console.readPassword怎么用?Java Console.readPassword使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.Console
的用法示例。
在下文中一共展示了Console.readPassword方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: userCredentials
import java.io.Console; //导入方法依赖的package包/类
/**
* ask user for Credentials
*/
private void userCredentials() {
AdvancedEncryptionStandard myEncryption = new AdvancedEncryptionStandard();
Scanner input = new Scanner(System.in, "utf-8");
Console console = System.console();
console.printf("Username: ");
this.username = input.nextLine();
//Password Field is not prompted
console.printf("Password: ");
char[] pass = console.readPassword();
this.decryptPassword = new String(pass);
//ecrypts input user password
this.encryptPassword = myEncryption.encrypt(decryptPassword);
this.password = encryptPassword;
System.out.println();
}
示例2: init
import java.io.Console; //导入方法依赖的package包/类
protected void init(String[] args) {
try {
parser.parseArgument(args);
} catch (CmdLineException e) {
System.err.println(e.getMessage());
parser.printUsage(System.err);
System.exit(1);
}
if (help) {
parser.printUsage(System.err);
System.exit(1);
}
if (!AuthScheme.NO_AUTH.equals(authScheme)) {
if (keyStorePath == null) {
System.err.println("keyStorePath is required when " +
"authScheme is " + authScheme);
parser.printUsage(System.err);
System.exit(1);
}
if (keyStorePassword == null) {
Console con = System.console();
char[] password = con.readPassword("Enter key store password: ");
keyStorePassword = new String(password);
}
}
}
示例3: main
import java.io.Console; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
Argon2 argon2 = Argon2ArgumentFactory.parseArguments(args);
char[] password;
final Console console = System.console();
if(console != null)
password = console.readPassword();
else{
password = new Scanner(System.in).next().toCharArray();
/* UNSAFE - only for testing purposes
like piping input into argon2 - echo password | java -jar argon2.jar saltsalt
*/
}
argon2.setPassword(password)
.hash();
argon2.printSummary();
}
示例4: readPasswordFromConsole
import java.io.Console; //导入方法依赖的package包/类
/**
* Prompts the user for the password on the console
*
* @param user
* the username
*
* @return the password
*
* @throws Exception
*/
private static String readPasswordFromConsole(String user) throws Exception {
Console c = System.console();
String password = "";
if (c == null) {
System.err.println("No console.");
System.out.println(String.format("You are logging in as: " + user + "\n"));
System.out.print(String.format("Enter the password of that user account: "));
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
password = br.readLine();
System.out.println("");
}
else {
c.format("You are logging in as: " + user + "\n");
char[] passwordChar = c.readPassword("Enter the password of that user account: ");
password = new String(passwordChar);
System.out.println("");
}
return new String(password);
}
示例5: main
import java.io.Console; //导入方法依赖的package包/类
public static void main(String[] args) {
Console console = System.console();
if (console != null) {
String user = new String(console.readLine("Enter User:", new Object[0]));
String pwd = new String(console.readPassword("Enter Password:", new Object[0]));
console.printf("User name is:%s", new Object[] { user });
console.printf("Password is:%s", new Object[] { pwd });
} else {
System.out.println("No Console!");
}
}
示例6: getCredentialFromConsole
import java.io.Console; //导入方法依赖的package包/类
/**
* @return
*/
private Credential getCredentialFromConsole(Credential credential) {
Console cons = System.console();
if (credential.getUsername() == null) {
LOG.info("Enter your kerberos (or, DB user name if DB is not DACT enabled): ");
credential.setUsername(cons.readLine());
}
if (!credential.isAuthenticationMethodProvided()) {
char[] passwd = cons.readPassword("%s", "Password:");
if (passwd != null) {
credential.setPassword(new String(passwd));
}
}
return credential;
}
示例7: defaultMFATokenSupplier
import java.io.Console; //导入方法依赖的package包/类
public static Supplier<MFAToken> defaultMFATokenSupplier() {
return () -> {
Console console = System.console();
String token = null;
if (console != null) {
char[] secretValue = console.readPassword("Enter MFA code: ");
if (secretValue != null) {
token = new String(secretValue);
}
} else {
// probably running in an IDE; fallback to plaintext
System.out.print("Enter MFA code: ");
Scanner scanner = new Scanner(System.in);
token = scanner.nextLine();
}
if (token == null || token.isEmpty()) {
throw new InvalidInputException("A non-empty MFA code must be entered");
}
return new MFAToken(token);
};
}
示例8: init
import java.io.Console; //导入方法依赖的package包/类
protected void init(String[] args) {
try {
parser.parseArgument(args);
} catch (CmdLineException e) {
System.err.println(e.getMessage());
parser.printUsage(System.err);
System.exit(1);
}
if (help) {
parser.printUsage(System.err);
System.exit(1);
}
if (!AuthScheme.NO_AUTH.equals(authScheme)) {
if (keyStorePath == null) {
System.err.println("keyStorePath is required when " +
"authScheme is " + authScheme);
parser.printUsage(System.err);
System.exit(1);
}
if (keyStorePassword == null) {
Console con = System.console();
char[] password = con.readPassword("Enter key store password: ");
keyStorePassword = new String(password);
}
}
}
示例9: getDBConnection
import java.io.Console; //导入方法依赖的package包/类
/**
* Get a JDBC connection to the database.
*
* @return the connection to the database
* @throws ClassNotFoundException if the JDBC driver specified can't be found
* @throws SQLException if a JDBC error occurs
*/
public Connection getDBConnection() throws ClassNotFoundException, SQLException {
String driver = properties.getProperty(SchemaDefPropertyValues.JDBC_DRIVER,
"**NOT_SET**");
String url = properties.getProperty(SchemaDefPropertyValues.JDBC_URL,
"**NOT_SET**");
String userName = properties.getProperty(SchemaDefPropertyValues.JDBC_USER,
"**NOT_SET**");
String password = properties.getProperty(SchemaDefPropertyValues.JDBC_PASSWORD,
"**NOT_SET**");
Connection connection;
if (password.equalsIgnoreCase("prompt")) {
Console cons;
char[] passwd;
if ((cons = System.console()) != null &&
(passwd = cons.readPassword("%n**********%n[%s] ",
"Enter JDBC Password:")) != null) {
password = new String(passwd);
}
else {
LOG.error("Failed to read passord from the command line");
}
}
// load the class for the JDBC driver
Class.forName(driver);
// get the database connection
connection = DriverManager.getConnection(url, userName, password);
return connection;
}
示例10: readPassword
import java.io.Console; //导入方法依赖的package包/类
@Override
public String readPassword(String prompt) {
Console console = System.console();
if (console != null) {
try {
return new String(console.readPassword(prompt));
} catch (Exception e) {
logger.warn("Password could not be read.", e);
}
} else {
logger.warn("Failed to read password due to System.console()");
}
println("Unable to read password securely. Reading password in cleartext.");
println("Press Ctrl+C to abort");
return readLine(prompt);
}
示例11: main
import java.io.Console; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
String path = System.getenv("LR");
if (path == null || path.isEmpty()) {
throw new RuntimeException("Bad value in environment variable");
}
File file = new File(path);
file.getParentFile().mkdirs();
Console console = System.console();
// read username and password
String user = console.readLine("Username: ");
char[] passwd = console.readPassword("Password: ");
// experiment with UserEndpoints.CredentialProvider
MyCredentials credentials = new MyCredentials(user, passwd);
RestUserEndpoints endpoints = new RestUserEndpoints();
// add HttpLoggingInterceptor, log as much ask possible
endpoints.addInterceptor(new HttpLoggingInterceptor(new MyLogger()).setLevel(HttpLoggingInterceptor.Level.BODY));
endpoints.setupEndpoints();
LoginResponse loginResponse = endpoints.doLogin(credentials);
// this should be done to minimize password leakage but other parts of library must be changed to support char arrays
Arrays.fill(passwd, '0');
// finally save LoginResponse to disk
String login = JsonFactory.GSON.toJson(loginResponse);
PrintWriter writer = new PrintWriter(file);
writer.print(login);
writer.close();
// just close JVM. Otherwise it will wait okio daemon timeouts
System.exit(0);
}
示例12: readPassword
import java.io.Console; //导入方法依赖的package包/类
protected void readPassword(Map<String, String> envArgs) throws Exception {
final Console cons = System.console();
if (cons == null) {
throw new IllegalStateException(
"No console found for reading the password.");
}
final char[] pwd = cons.readPassword(LocalizedResource
.getMessage("UTIL_password_Prompt"));
if (pwd != null) {
final String passwd = new String(pwd);
// encrypt the password with predefined key that is salted with host IP
final byte[] keyBytes = getBytesEnv();
envArgs.put(ENV1, GemFireXDUtils.encrypt(passwd, null, keyBytes));
}
}
示例13: readChars
import java.io.Console; //导入方法依赖的package包/类
/**
* @see JdkHelper#readChars(InputStream, boolean)
*/
@Override
public final String readChars(final InputStream in, final boolean noecho) {
final Console console;
if (noecho && (console = System.console()) != null) {
return new String(console.readPassword());
}
else {
return super.readChars(in, noecho);
}
}
示例14: getConsoleInstance
import java.io.Console; //导入方法依赖的package包/类
/**
* Creates an instance that prompts the console user to enter data after prompts.
* @prompt A String prompt to be displayed for the user on the console.
* @noEcho A boolean indicating if the user-entered text should be hidden from the console; usually for passwords.
*/
public static final UserInterface getConsoleInstance()
{
return new UserInterface()
{
@Override public String getUserInput(String prompt, boolean noEcho, TAC_PLUS.AUTHEN.STATUS getWhat)
{
Console console = System.console();
if (console == null) { System.out.println("No console available!"); return null; }
System.out.println();
System.out.print(prompt);
String input = noEcho? new String(console.readPassword()) : console.readLine();
if (getWhat == TAC_PLUS.AUTHEN.STATUS.GETUSER) { this.username = input; }
return input;
}
};
}
示例15: main
import java.io.Console; //导入方法依赖的package包/类
public static void main(String[] args) {
Console cons;
if ((cons = System.console()) != null) {
char[] passwd = null;
try {
passwd = cons.readPassword("Password:");
// In real life you would send the password into authentication code
System.out.println("Your password was: " + new String(passwd));
} finally {
// Shred this in-memory copy for security reasons
if (passwd != null) {
java.util.Arrays.fill(passwd, ' ');
}
}
} else {
throw new RuntimeException("No console, can't get password");
}
}