当前位置: 首页>>代码示例>>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;未经允许,请勿转载。