disable console echo when reading secure info

This commit is contained in:
Jonathan Shook 2020-07-15 13:39:52 -05:00
parent 9d2e808664
commit ca81e1bcb4

View File

@ -3,6 +3,7 @@ package io.nosqlbench.driver.jmx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.Console;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
@ -24,24 +25,10 @@ public class SecureUtils {
throw new RuntimeException(e);
}
} else if (source.startsWith("console:")||source.equals("")) {
System.out.println("")
StringBuilder sb = new StringBuilder();
char in=0;
while (true) {
try {
in= (char)System.in.read();
} catch (IOException e) {
throw new RuntimeException(e);
}
if (in!='\n' && in!='\r') {
sb.append(in);
} else {
break;
}
}
return sb.toString();
System.out.print("Enter " + description+":");
char[] chars = System.console().readPassword("%s:",description);
return new String(chars);
} else {
logger.warn("Parameter for '" + description + "' was passed directly. This is less secure." +
" Consider using 'file:<file>' or 'console:' for this value instead");