當前位置: 首頁>>代碼示例>>Java>>正文


Java Console.readPassword方法代碼示例

本文整理匯總了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();
}
 
開發者ID:GrigorisParaskevakos,項目名稱:BankAccount_PasaskevakosG_BootCamp3,代碼行數:20,代碼來源:LoginScreen.java

示例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);
        }
    }
}
 
開發者ID:zhenshengcai,項目名稱:floodlight-hardware,代碼行數:27,代碼來源:AuthTool.java

示例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();
    }
 
開發者ID:andreas1327250,項目名稱:argon2-java,代碼行數:21,代碼來源:Main.java

示例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);
}
 
開發者ID:hpclab,項目名稱:TheMatrixProject,代碼行數:33,代碼來源:IadCreator.java

示例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!");
	}
}
 
開發者ID:leon66666,項目名稱:JavaCommon,代碼行數:12,代碼來源:ConsoleDemo.java

示例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;
}
 
開發者ID:goldmansachs,項目名稱:obevo,代碼行數:20,代碼來源:CredentialReader.java

示例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);
    };
}
 
開發者ID:schibsted,項目名稱:strongbox,代碼行數:25,代碼來源:MFAToken.java

示例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);
        }
    }
}
 
開發者ID:xuraylei,項目名稱:fresco_floodlight,代碼行數:27,代碼來源:AuthTool.java

示例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;
}
 
開發者ID:oracle,項目名稱:bdglue,代碼行數:42,代碼來源:SchemaDef.java

示例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);
}
 
開發者ID:testmycode,項目名稱:tmc-cli,代碼行數:17,代碼來源:TerminalIo.java

示例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);
}
 
開發者ID:progwml6,項目名稱:JavaCurseAPI,代碼行數:34,代碼來源:AuthTokenGenerator.java

示例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));
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:16,代碼來源:GfxdServerLauncher.java

示例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);
  }
}
 
開發者ID:gemxd,項目名稱:gemfirexd-oss,代碼行數:14,代碼來源:Jdk6Helper.java

示例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;
		}
	};
}
 
開發者ID:AugurSystems,項目名稱:TACACS,代碼行數:22,代碼來源:UserInterface.java

示例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");
    }
}
 
開發者ID:shashanksingh28,項目名稱:code-similarity,代碼行數:19,代碼來源:ReadPassword.java


注:本文中的java.io.Console.readPassword方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。