java.io.Console.readPassword()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(4.9k)|赞(0)|评价(0)|浏览(310)

本文整理了Java中java.io.Console.readPassword()方法的一些代码示例,展示了Console.readPassword()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Console.readPassword()方法的具体详情如下:
包路径:java.io.Console
类名称:Console
方法名:readPassword

Console.readPassword介绍

[英]Reads a password from the console. The password will not be echoed to the display.
[中]从控制台读取密码。密码不会回显到显示屏上。

代码示例

代码示例来源:origin: neo4j/neo4j

@Override
public char[] promptPassword( String fmt, Object... args )
{
  return console.readPassword( fmt, args );
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public char[] readPassword(String fmt, Object... args) {
  return delegate.readPassword(fmt, args);
}

代码示例来源:origin: web3j/web3j

@Override
  public char[] readPassword(String fmt, Object... args) {
    return console.readPassword(fmt, args);
  }
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
@Override public char[] readPassword() {
  return delegate.readPassword();
}

代码示例来源:origin: jenkinsci/jenkins

public String call() throws IOException {
  Console console = System.console();
  if (console == null)    return null;    // no terminal
  char[] w = console.readPassword("Password:");
  if (w==null)    return null;
  return new String(w);
}

代码示例来源:origin: jenkinsci/jenkins

private static String askForPasswd(String filePath){
  Console cons = System.console();
  String passwd = null;
  if (cons != null){
    char[] p = cons.readPassword("%s", "Enter passphrase for " + filePath + ":");
    passwd = String.valueOf(p);
  }
  return passwd;
}

代码示例来源:origin: neo4j/neo4j

@Override
public char[] promptPassword( String fmt, Object... args )
{
  return System.console().readPassword( fmt, args );
}

代码示例来源:origin: apache/nifi

@Override
public char[] readPassword() throws ConsoleException {
  return console.readPassword();
}

代码示例来源:origin: elastic/elasticsearch-hadoop

@Override
  public char[] readPassword(String prompt, Object... args) {
    if (console == null) {
      throw new IllegalStateException("Cannot disable console echo to read password");
    }
    return this.console.readPassword(prompt, args);
  }
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

public char[] readPassword(String prompt) {
 Console console = System.console();
 char[] pass = console.readPassword(prompt);
 return pass;
}

代码示例来源:origin: prestodb/presto

private String getPassword()
{
  checkState(clientOptions.user != null, "Username must be specified along with password");
  String defaultPassword = System.getenv("PRESTO_PASSWORD");
  if (defaultPassword != null) {
    return defaultPassword;
  }
  java.io.Console console = System.console();
  if (console == null) {
    throw new RuntimeException("No console from which to read password");
  }
  char[] password = console.readPassword("Password: ");
  if (password != null) {
    return new String(password);
  }
  return "";
}

代码示例来源:origin: floragunncom/search-guard

private static String promptForPassword(String passwordName, String commandLineOption, String envVarName) throws Exception {
  final Console console = System.console();
  if(console == null) {
    throw new Exception("Cannot allocate a console. Set env var "+envVarName+" or "+commandLineOption+" on commandline in that case");
  }
  return new String(console.readPassword("[%s]", passwordName+" password:"));
}

代码示例来源:origin: apache/incubator-gobblin

public static char[] getPasswordFromConsole() {
 System.out.print("Please enter the keystore password: ");
 return System.console().readPassword();
}

代码示例来源:origin: apache/incubator-gobblin

private static String getPasswordFromConsole() {
  System.out.print("Please enter the keystore password: ");
  return new String(System.console().readPassword());
 }
}

代码示例来源:origin: apache/geode

public char[] readPassword(String textToPrompt) {
 if (isSupported()) {
  return console.readPassword(textToPrompt);
 }
 return null;
}

代码示例来源:origin: syncany/syncany

public char[] readPassword() {
  if (console == null) {
    return readLine().toCharArray();
  }
  else {
    return console.readPassword();
  }
}

代码示例来源:origin: hierynomus/sshj

@Override
public char[] reqPassword(Resource<?> resource) {
  numTries++;
  if (console == null) {
    // the request cannot be serviced
    return null;
  }
  return console.readPassword(promptFormat, resource.toString());
}

代码示例来源:origin: syncany/syncany

public char[] readPassword(String fmt, Object... args) {
  if (console == null) {
    getSystemOutWriter().write(String.format(fmt, args));
    return readLine().toCharArray();
  }
  else {
    return console.readPassword(fmt, args);
  }
}

代码示例来源:origin: lealone/Lealone

private String readPassword() throws IOException {
  java.io.Console console = System.console();
  if (console != null) {
    char[] password = console.readPassword("Password  ");
    return password == null ? null : new String(password);
  } else { // In Eclipse, use the default solution
    print("Password  ");
    return readLine();
  }
}

代码示例来源:origin: hierynomus/sshj

@Test
public void testReqPassword() {
  char[] expectedPassword = "password".toCharArray();
  Console console = Mockito.mock(Console.class);
  Mockito.when(console.readPassword(Mockito.anyString(), Mockito.any()))
      .thenReturn(expectedPassword);
  Resource resource = Mockito.mock(Resource.class);
  char[] password = new ConsolePasswordFinder(console).reqPassword(resource);
  Assert.assertArrayEquals("Password should match mocked return value",
      expectedPassword, password);
  Mockito.verifyNoMoreInteractions(resource);
}

相关文章