/**
* 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();
}
java类java.io.Console的实例源码
LoginScreen.java 文件源码
项目:BankAccount_PasaskevakosG_BootCamp3
阅读 33
收藏 0
点赞 0
评论 0
SmartContentDemo.java 文件源码
项目:dataninja-smartcontent-api-sdk-java
阅读 27
收藏 0
点赞 0
评论 0
/**
* Run through the Smart Content APIs and show usage
*/
public void process() {
SmartContentApi client = new SmartContentClient().getClient();
String input;
Console cmdline = System.console();
if (cmdline == null) {
System.err.println("No console for command line demo.");
System.exit(1);
}
// Find a Smart Data concept
input = cmdline.readLine("Enter text to find concepts, categories or entities: ");
System.out.println(findSmartContentDemo(client, input).toString());
}
AuthTool.java 文件源码
项目:floodlight-hardware
阅读 18
收藏 0
点赞 0
评论 0
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);
}
}
}
Main.java 文件源码
项目:light
阅读 18
收藏 0
点赞 0
评论 0
private void doConsole() throws Exception
{
Console console = System.console();
if (console != null) // IDE not support
{
String className = console.readLine("> ");
CommandManager commandManager = new CommandManager();
while (commandManager.execute(new CommandFactory().createCommand(className)))
{
console.printf(NEW_LINE);
className = console.readLine("> ");
}
}
}
Encryption.java 文件源码
项目:identity-agent-sso
阅读 19
收藏 0
点赞 0
评论 0
/**
* Main entry point.
*
* @param args The password you wanted to encrypt.
* @throws Exception If an error occurred.
*/
public static void main(String[] args) {
String encryptedVal;
Console console = System.console();
if (console == null) {
System.err.println("Couldn't get Console instance");
System.exit(0);
}
// Get the password used for encryption.
char passwordArray[] = console.readPassword("Please Enter a password you want to use for the encryption: ");
try {
encryptedVal = encrypt(args[0], passwordArray);
Files.write(Paths.get("./encrypted_password.txt"), encryptedVal.getBytes(StandardCharsets.UTF_8));
} catch (EncryptingException | IOException ex) {
System.err.println("Error occurred while encrypting or while writing in to the file ");
ex.printStackTrace();
return;
}
Arrays.fill(passwordArray, (char) 0);
System.out.println("File with encrypted value created successfully in your current location");
}
AuthTool.java 文件源码
项目:ACAMPController
阅读 24
收藏 0
点赞 0
评论 0
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);
}
}
}
Echo.java 文件源码
项目:ocpjp
阅读 20
收藏 0
点赞 0
评论 0
public static void main( String[] args ) {
String str = " ";
String[] splited = str.split( " " );
System.out.println( "-> " + splited.length );
Console console = System.console();
/*
* Se a JVM é invocada indiretamente pela IDE, ou se a JVM é invocada a
* partir de um processo de background, então o chamada de método
* System.console () irá falhar e retornar nulo.
*/
if ( console == null ) {
System.out.println(
"Executando app de uma ide... objeto console nao recuperado" );
}
else {
console.printf( console.readLine() );
}
}
SpecialCharHandling.java 文件源码
项目:ocpjp
阅读 17
收藏 0
点赞 0
评论 0
public static void main( String[] args ) {
double d = -19.080808;
System.out.println( "-> " + String.valueOf( d ) );
// string tem 2 caracteres Scandinavos
String scandString = "å, ä, and ö";
// tentando exibir caracteres scandinavos diretamente com println
System.out.println(
"Printing scands directly with println: " + scandString );
// agora com um objeto console
Console console = System.console();
if ( console != null ) {
console.printf(
"Printing scands thro' console's printf method: " + scandString );
}
}
IadCreator.java 文件源码
项目:TheMatrixProject
阅读 21
收藏 0
点赞 0
评论 0
/**
* 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);
}
StandaloneClient.java 文件源码
项目:documents4j
阅读 20
收藏 0
点赞 0
评论 0
private static DocumentType[] configureConversion(Console console, Map<DocumentType, Set<DocumentType>> supportedConversions) {
console.printf("The connected converter supports the following conversion formats:%n");
Map<Integer, DocumentType[]> conversionsByIndex = new HashMap<Integer, DocumentType[]>();
int index = 0;
for (Map.Entry<DocumentType, Set<DocumentType>> entry : supportedConversions.entrySet()) {
for (DocumentType targetType : entry.getValue()) {
conversionsByIndex.put(index, new DocumentType[]{entry.getKey(), targetType});
console.printf(" | [%d]: '%s' -> '%s'%n", index++, entry.getKey(), targetType);
}
}
do {
console.printf("Enter the number of the conversion you want to perform: ");
try {
int choice = Integer.parseInt(console.readLine());
DocumentType[] conversion = conversionsByIndex.get(choice);
if (conversion != null) {
console.printf("Converting '%s' to '%s'. You can change this setup by entering '\\f'.%n", conversion[0], conversion[1]);
return conversion;
}
console.printf("The number you provided is not among the legal choices%n");
} catch (RuntimeException e) {
console.printf("You did not provide a number%n");
}
} while (true);
}
ConsoleDemo.java 文件源码
项目:JavaCommon
阅读 17
收藏 0
点赞 0
评论 0
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!");
}
}
CredentialReader.java 文件源码
项目:obevo
阅读 18
收藏 0
点赞 0
评论 0
/**
* @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;
}
MFAToken.java 文件源码
项目:strongbox
阅读 20
收藏 0
点赞 0
评论 0
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);
};
}
PasteAndMeasurementsUITest.java 文件源码
项目:openjdk-jdk10
阅读 18
收藏 0
点赞 0
评论 0
public void testPrevNextSnippet() throws Exception {
System.setProperty(ANSI_SUPPORTED_PROPERTY, "true");
Field cons = System.class.getDeclaredField("cons");
cons.setAccessible(true);
Constructor console = Console.class.getDeclaredConstructor();
console.setAccessible(true);
cons.set(null, console.newInstance());
doRunTest((inputSink, out) -> {
inputSink.write("void test1() {\nSystem.err.println(1);\n}\n" + LOC +
"void test2() {\nSystem.err.println(1);\n}\n" + LOC + LOC + LOC + LOC + LOC);
waitOutput(out, "\u001b\\[6nvoid test1\\(\\) \\{\n" +
"\u0006\u001b\\[6nSystem.err.println\\(1\\);\n" +
"\u0006\u001b\\[6n\\}\n" +
"\\| created method test1\\(\\)\n" +
"\u0005\u001b\\[6nvoid test2\\(\\) \\{\n" +
"\u0006\u001b\\[6nSystem.err.println\\(1\\);\n" +
"\u0006\u001b\\[6n\\}\n" +
"\\| created method test2\\(\\)\n" +
"\u0005\u001b\\[6n");
});
}
AuthTool.java 文件源码
项目:fresco_floodlight
阅读 19
收藏 0
点赞 0
评论 0
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);
}
}
}
Main.java 文件源码
项目:argon2-java
阅读 18
收藏 0
点赞 0
评论 0
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();
}
AuthTool.java 文件源码
项目:iTAP-controller
阅读 20
收藏 0
点赞 0
评论 0
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);
}
}
}
AuthTool.java 文件源码
项目:SDN-Multicast
阅读 20
收藏 0
点赞 0
评论 0
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);
}
}
}
DatabaseInstallation.java 文件源码
项目:MCS-Master
阅读 16
收藏 0
点赞 0
评论 0
private MongoDBConfig mongodbInstall() {
MongoDBConfig mongoDBConfig;
String ip;
String port;
do {
Console console = System.console();
log.info("Please enter the ip for MongoDB");
ip = console.readLine();
log.info("Please enter the port");
port = console.readLine();
mongoDBConfig = new MongoDBConfig();
mongoDBConfig.setIp(ip);
mongoDBConfig.setPort(port);
log.info("Please wait");
} while (!MongoDBConnectionTest.connectionTest(mongoDBConfig));
return mongoDBConfig;
}
SchemaDef.java 文件源码
项目:bdglue
阅读 19
收藏 0
点赞 0
评论 0
/**
* 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;
}
AuthTool.java 文件源码
项目:arscheduler
阅读 22
收藏 0
点赞 0
评论 0
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);
}
}
}
AuthTokenGenerator.java 文件源码
项目:JavaCurseAPI
阅读 17
收藏 0
点赞 0
评论 0
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);
}
ConsoleLoginHandlerFactory.java 文件源码
项目:QD
阅读 17
收藏 0
点赞 0
评论 0
@Override
public void run() {
try {
CONSOLE_LOCK.lockInterruptibly();
} catch (InterruptedException e) {
return; // don't need to login anymore -- promise was cancelled
}
try {
String user = factoryUser;
String password = factoryPassword;
Console console = System.console();
if (console == null) {
Scanner scanner = new Scanner(System.in);
System.out.println(reason);
if (user.isEmpty()) {
System.out.print(USER);
user = scanner.nextLine();
}
if (password.isEmpty()) {
System.out.print(PASSWORD);
password = scanner.nextLine();
}
} else {
console.format("%s%n", reason);
if (user.isEmpty())
user = console.readLine(USER);
if (password.isEmpty())
password = String.valueOf(console.readPassword(PASSWORD));
}
done(AuthToken.createBasicToken(user, password));
} finally {
CONSOLE_LOCK.unlock();
}
}
GfxdServerLauncher.java 文件源码
项目:gemfirexd-oss
阅读 18
收藏 0
点赞 0
评论 0
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));
}
}
Jdk6Helper.java 文件源码
项目:gemfirexd-oss
阅读 18
收藏 0
点赞 0
评论 0
/**
* @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);
}
}
AuthTool.java 文件源码
项目:QoS-floodlight
阅读 25
收藏 0
点赞 0
评论 0
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);
}
}
}
ShellCommand.java 文件源码
项目:baratine
阅读 22
收藏 0
点赞 0
评论 0
private String readCommand(Console console, String prompt)
{
String command = readLine(console, prompt);
if (command == null) {
return null;
}
while (command.endsWith("\\")) {
command = command.substring(0, command.length() - 1);
String line = readLine(console, "> ");
if (line == null) {
return null;
}
command += line;
}
return command;
}
ShellCommandOld.java 文件源码
项目:baratine
阅读 18
收藏 0
点赞 0
评论 0
private String readCommand(Console console, String prompt)
{
String command = readLine(console, prompt);
if (command == null) {
return null;
}
while (command.endsWith("\\")) {
command = command.substring(0, command.length() - 1);
String line = readLine(console, "> ");
if (line == null) {
return null;
}
command += line;
}
return command;
}
UserInterface.java 文件源码
项目:TACACS
阅读 26
收藏 0
点赞 0
评论 0
/**
* 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;
}
};
}
AuthTool.java 文件源码
项目:floodlight1.2-delay
阅读 23
收藏 0
点赞 0
评论 0
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);
}
}
}