protected char[] readPassword(String prompt) throws IOException { String tmpPrompt = (prompt == null) ? "Password:" : prompt.trim(); if (!tmpPrompt.endsWith(":")) { tmpPrompt += ":"; } String passwordUi = System.getProperty("org.xipki.console.passwordui"); return "gui".equalsIgnoreCase(passwordUi) ? SecurePasswordInputPanel.readPassword(tmpPrompt) : readLine(tmpPrompt, '*').toCharArray(); }
public static char[] readPassword(String prompt) { LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel(); try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception ex) { // CHECKSTYLE:SKIP } try { SecurePasswordInputPanel gui = new SecurePasswordInputPanel(); String[] options = new String[]{OK}; String tmpPrompt = prompt; if (tmpPrompt == null || tmpPrompt.isEmpty()) { tmpPrompt = "Password required"; } int option = JOptionPane.showOptionDialog(null, gui, tmpPrompt, JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (option == 0) { // pressing OK button return gui.getPassword(); } else { return null; } } finally { try { UIManager.setLookAndFeel(currentLookAndFeel); } catch (UnsupportedLookAndFeelException ex) { // CHECKSTYLE:SKIP } } } // method readPassword
protected char[] readPassword(String prompt) throws IOException { String tmpPrompt = (prompt == null) ? "Password:" : prompt.trim(); if (!tmpPrompt.endsWith(":")) { tmpPrompt += ":"; } String passwordUi = System.getProperty("org.xipki.console.passwordui"); return "gui".equalsIgnoreCase(passwordUi) ? SecurePasswordInputPanel.readPassword(tmpPrompt) : readLine(tmpPrompt, '*').toCharArray(); }
protected char[] readPassword(final String prompt) throws IOException { String tmpPrompt = (prompt == null) ? "Password:" : prompt.trim(); if (!tmpPrompt.endsWith(":")) { tmpPrompt += ":"; } String passwordUi = System.getProperty("org.xipki.console.passwordui"); return "gui".equalsIgnoreCase(passwordUi) ? SecurePasswordInputPanel.readPassword(tmpPrompt) : readLine(tmpPrompt, '*').toCharArray(); }
@Override public char[] getPassword(String prompt, String testToken) throws PasswordResolverException { String tmpPrompt = prompt; if (StringUtil.isBlank(tmpPrompt)) { tmpPrompt = "Password required"; } for (int i = 0; i < tries; i++) { char[] password; if (quorum == 1) { password = SecurePasswordInputPanel.readPassword(tmpPrompt); if (password == null) { throw new PasswordResolverException("user has cancelled"); } } else { char[][] passwordParts = new char[quorum][]; for (int j = 0; j < quorum; j++) { String promptPart = tmpPrompt + " (part " + (j + 1) + "/" + quorum + ")"; passwordParts[j] = SecurePasswordInputPanel.readPassword(promptPart); if (passwordParts[j] == null) { throw new PasswordResolverException("user has cancelled"); } } password = StringUtil.merge(passwordParts); } if (isPasswordValid(password, testToken)) { return password; } } throw new PasswordResolverException("Could not get the password after " + tries + " tries"); }