List of usage examples for javax.swing JPasswordField getPassword
@BeanProperty(bound = false) public char[] getPassword()
TextComponent
. From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(200, 200);//from w ww . j ava 2 s . c om frame.setVisible(true); JOptionPane.showMessageDialog(frame, "A"); JOptionPane.showMessageDialog(frame, "B", "message", JOptionPane.WARNING_MESSAGE); int result = JOptionPane.showConfirmDialog(null, "Remove now?"); switch (result) { case JOptionPane.YES_OPTION: System.out.println("Yes"); break; case JOptionPane.NO_OPTION: System.out.println("No"); break; case JOptionPane.CANCEL_OPTION: System.out.println("Cancel"); break; case JOptionPane.CLOSED_OPTION: System.out.println("Closed"); break; } String name = JOptionPane.showInputDialog(null, "Please enter your name."); System.out.println(name); JTextField userField = new JTextField(); JPasswordField passField = new JPasswordField(); String message = "Please enter your user name and password."; result = JOptionPane.showOptionDialog(frame, new Object[] { message, userField, passField }, "Login", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.OK_OPTION) System.out.println(userField.getText() + " " + new String(passField.getPassword())); }
From source file:kevin.gvmsgarch.App.java
private static String getPassword() { String retval = null;//w w w . ja v a2 s . com JPasswordField pwd = new JPasswordField(20); int optionSelected = JOptionPane.showConfirmDialog(null, pwd, "Enter Password", JOptionPane.OK_CANCEL_OPTION); if (optionSelected == JOptionPane.OK_OPTION) { retval = new String(pwd.getPassword()); } return retval; }
From source file:net.minder.KnoxWebHdfsJavaClientExamplesTest.java
@BeforeClass public static void setupSuite() { Console console = System.console(); if (console != null) { console.printf("Knox Host: "); KNOX_HOST = console.readLine();// www. j ava2 s. c om console.printf("Topology : "); TOPOLOGY_PATH = console.readLine(); console.printf("Username : "); TEST_USERNAME = console.readLine(); console.printf("Password: "); TEST_PASSWORD = new String(console.readPassword()); } else { JLabel label = new JLabel("Enter Knox host, topology, username, password:"); JTextField host = new JTextField(KNOX_HOST); JTextField topology = new JTextField(TOPOLOGY_PATH); JTextField username = new JTextField(TEST_USERNAME); JPasswordField password = new JPasswordField(TEST_PASSWORD); int choice = JOptionPane.showConfirmDialog(null, new Object[] { label, host, topology, username, password }, "Credentials", JOptionPane.OK_CANCEL_OPTION); assertThat(choice, is(JOptionPane.YES_OPTION)); TEST_USERNAME = username.getText(); TEST_PASSWORD = new String(password.getPassword()); KNOX_HOST = host.getText(); TOPOLOGY_PATH = topology.getText(); } TOPOLOGY_URL = String.format("%s://%s:%d/%s/%s", KNOX_SCHEME, KNOX_HOST, KNOX_PORT, KNOX_PATH, TOPOLOGY_PATH); WEBHDFS_URL = String.format("%s/%s", TOPOLOGY_URL, WEBHDFS_PATH); }
From source file:edu.harvard.mcz.imagecapture.LoginDialog.java
public static String hashPassword(JPasswordField ajPasswordField) { return HashUtility.getSHA1Hash(String.valueOf(ajPasswordField.getPassword())); }
From source file:com.palantir.ptoss.cinch.swing.JPasswordFieldWiringHarness.java
public static Collection<Binding> bindJPasswordField(final BindableModel model, final JPasswordField pwdField, final Method getter, final Method setter) { pwdField.getDocument().addDocumentListener(new DocumentListener() { public void removeUpdate(DocumentEvent e) { updateModel();/*from www . j a va 2s . co m*/ } public void insertUpdate(DocumentEvent e) { updateModel(); } public void changedUpdate(DocumentEvent e) { updateModel(); } private void updateModel() { try { setter.invoke(model, pwdField.getPassword()); } catch (Exception ex) { Wiring.logger.error("exception in JPasswordField binding", ex); } } }); Binding binding = new Binding() { public <T extends Enum<?> & ModelUpdate> void update(T... changed) { try { char[] charArray = (char[]) getter.invoke(model); if (charArray == null) { charArray = new char[0]; } if (!Arrays.equals(charArray, pwdField.getPassword())) { pwdField.setText(String.valueOf(charArray)); } } catch (Exception ex) { Wiring.logger.error("exception in JPasswordField binding", ex); } } }; model.bind(binding); return Collections.singleton(binding); }
From source file:com.microsoftopentechnologies.intellij.helpers.AndroidStudioHelper.java
public static void deleteActivityTemplates(Object caller) throws IOException, InterruptedException { String[] cmd = null;//from w w w . ja v a2 s. c om String templatePath = URLDecoder .decode(ApplicationComponent.class.getResource("").getPath().replace("file:/", ""), "UTF-8"); templatePath = templatePath.replace("/", File.separator); templatePath = templatePath.substring(0, templatePath.indexOf(File.separator + "lib")); templatePath = templatePath + File.separator + "plugins" + File.separator + "android" + File.separator; templatePath = templatePath + "lib" + File.separator + "templates" + File.separator + "activities" + File.separator; String[] env = null; String tmpdir = getTempLocation(); BufferedInputStream bufferedInputStream = new BufferedInputStream( ServiceCodeReferenceHelper.getTemplateResource("ActivityTemplate.zip")); unZip(bufferedInputStream, tmpdir); if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { try { VirtualFile mobileTemplate = LocalFileSystem.getInstance() .findFileByIoFile(new File(templatePath + mobileServicesTemplateName)); VirtualFile officeTemplate = LocalFileSystem.getInstance() .findFileByIoFile(new File(templatePath + officeTemplateName)); if (mobileTemplate != null) mobileTemplate.delete(caller); if (officeTemplate != null) officeTemplate.delete(caller); } catch (IOException ex) { PrintWriter printWriter = new PrintWriter(tmpdir + "\\script.bat"); printWriter.println("@echo off"); printWriter.println("del \"" + templatePath + mobileServicesTemplateName + "\" /Q /S"); printWriter.println("del \"" + templatePath + officeTemplateName + "\" /Q /S"); printWriter.flush(); printWriter.close(); String[] tmpcmd = { tmpdir + "\\elevate.exe", "script.bat", "1" }; cmd = tmpcmd; ArrayList<String> tempenvlist = new ArrayList<String>(); for (String envval : System.getenv().keySet()) tempenvlist.add(String.format("%s=%s", envval, System.getenv().get(envval))); tempenvlist.add("PRECOMPILE_STREAMLINE_FILES=1"); env = new String[tempenvlist.size()]; tempenvlist.toArray(env); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(cmd, env, new File(tmpdir)); proc.waitFor(); } } else if (System.getProperty("os.name").toLowerCase().startsWith("mac")) { VirtualFile mobileTemplate = LocalFileSystem.getInstance() .findFileByIoFile(new File(templatePath + mobileServicesTemplateName)); VirtualFile officeTemplate = LocalFileSystem.getInstance() .findFileByIoFile(new File(templatePath + officeTemplateName)); if (mobileTemplate != null && officeTemplate != null) { exec(new String[] { "osascript", "-e", "do shell script \"rm -r \\\"/" + templatePath + mobileServicesTemplateName + "\\\"\"", "-e", "do shell script \"rm -r \\\"/" + templatePath + officeTemplateName + "\\\"\"" }, tmpdir); } } else { try { VirtualFile mobileTemplate = LocalFileSystem.getInstance() .findFileByIoFile(new File(templatePath + mobileServicesTemplateName)); VirtualFile officeTemplate = LocalFileSystem.getInstance() .findFileByIoFile(new File(templatePath + officeTemplateName)); mobileTemplate.delete(caller); officeTemplate.delete(caller); } catch (IOException ex) { JPasswordField pf = new JPasswordField(); int okCxl = JOptionPane.showConfirmDialog(null, pf, "To copy Microsoft Services templates, the plugin needs your password:", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (okCxl == JOptionPane.OK_OPTION) { String password = new String(pf.getPassword()); exec(new String[] { "echo", password, "|", "sudo", "-S", "rm", "-r", tmpdir + mobileServicesTemplateName, templatePath + mobileServicesTemplateName }, tmpdir); exec(new String[] { "echo", password, "|", "sudo", "-S", "rm", "-r", tmpdir + officeTemplateName, templatePath + officeTemplateName }, tmpdir); } } } }
From source file:com.microsoftopentechnologies.intellij.helpers.AndroidStudioHelper.java
public static void newActivityTemplateManager() throws IOException, InterruptedException { String[] cmd = null;//from w w w .j a v a 2 s.co m String templatePath = URLDecoder .decode(ApplicationComponent.class.getResource("").getPath().replace("file:/", ""), "UTF-8"); templatePath = templatePath.replace("/", File.separator); templatePath = templatePath.substring(0, templatePath.indexOf(File.separator + "lib")); templatePath = templatePath + File.separator + "plugins" + File.separator + "android" + File.separator; templatePath = templatePath + "lib" + File.separator + "templates" + File.separator + "activities" + File.separator; String[] env = null; if (!new File(templatePath + mobileServicesTemplateName).exists()) { String tmpdir = getTempLocation(); BufferedInputStream bufferedInputStream = new BufferedInputStream( ServiceCodeReferenceHelper.getTemplateResource("ActivityTemplate.zip")); unZip(bufferedInputStream, tmpdir); if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { try { copyFolder(new File(tmpdir + mobileServicesTemplateName), new File(templatePath + mobileServicesTemplateName)); copyFolder(new File(tmpdir + officeTemplateName), new File(templatePath + officeTemplateName)); } catch (IOException ex) { PrintWriter printWriter = new PrintWriter(tmpdir + "\\script.bat"); printWriter.println("@echo off"); printWriter.println("md \"" + templatePath + mobileServicesTemplateName + "\""); printWriter.println("md \"" + templatePath + officeTemplateName + "\""); printWriter.println("xcopy \"" + tmpdir + mobileServicesTemplateName + "\" \"" + templatePath + mobileServicesTemplateName + "\" /s /i /Y"); printWriter.println("xcopy \"" + tmpdir + officeTemplateName + "\" \"" + templatePath + officeTemplateName + "\" /s /i /Y"); printWriter.flush(); printWriter.close(); String[] tmpcmd = { tmpdir + "\\elevate.exe", "script.bat", "1" }; cmd = tmpcmd; ArrayList<String> tempenvlist = new ArrayList<String>(); for (String envval : System.getenv().keySet()) tempenvlist.add(String.format("%s=%s", envval, System.getenv().get(envval))); tempenvlist.add("PRECOMPILE_STREAMLINE_FILES=1"); env = new String[tempenvlist.size()]; tempenvlist.toArray(env); Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(cmd, env, new File(tmpdir)); proc.waitFor(); //wait for elevate command to finish Thread.sleep(3000); if (!new File(templatePath + mobileServicesTemplateName).exists()) UIHelper.showException( "Error copying template files. Please refer to documentation to copy manually.", new Exception()); } } else { if (System.getProperty("os.name").toLowerCase().startsWith("mac")) { String[] strings = { "osascript", // "-e", // "do shell script \"mkdir -p \\\"/" + templatePath + mobileServicesTemplateName + "\\\"\"", // "-e", // "do shell script \"mkdir -p \\\"/" + templatePath + officeTemplateName + "\\\"\"", "-e", "do shell script \"cp -Rp \\\"" + tmpdir + mobileServicesTemplateName + "\\\" \\\"/" + templatePath + "\\\"\"", "-e", "do shell script \"cp -Rp \\\"" + tmpdir + officeTemplateName + "\\\" \\\"/" + templatePath + "\\\"\"" }; exec(strings, tmpdir); } else { try { copyFolder(new File(tmpdir + mobileServicesTemplateName), new File(templatePath + mobileServicesTemplateName)); copyFolder(new File(tmpdir + officeTemplateName), new File(templatePath + officeTemplateName)); } catch (IOException ex) { JPasswordField pf = new JPasswordField(); int okCxl = JOptionPane.showConfirmDialog(null, pf, "To copy Microsoft Services templates, the plugin needs your password:", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (okCxl == JOptionPane.OK_OPTION) { String password = new String(pf.getPassword()); exec(new String[] { "echo", password, "|", "sudo", "-S", "cp", "-Rp", tmpdir + mobileServicesTemplateName, templatePath + mobileServicesTemplateName }, tmpdir); exec(new String[] { "echo", password, "|", "sudo", "-S", "cp", "-Rp", tmpdir + officeTemplateName, templatePath + officeTemplateName }, tmpdir); } } } } } }
From source file:com.piusvelte.taplock.server.TapLockServer.java
private static void initialize() { (new File(APP_PATH)).mkdir(); if (OS == OS_WIN) Security.addProvider(new BouncyCastleProvider()); System.out.println("APP_PATH: " + APP_PATH); try {//from w ww. j a v a 2 s . co m sLogFileHandler = new FileHandler(sLog); } catch (SecurityException e) { writeLog("sLogFileHandler init: " + e.getMessage()); } catch (IOException e) { writeLog("sLogFileHandler init: " + e.getMessage()); } File propertiesFile = new File(sProperties); if (!propertiesFile.exists()) { try { propertiesFile.createNewFile(); } catch (IOException e) { writeLog("propertiesFile.createNewFile: " + e.getMessage()); } } Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); if (prop.isEmpty()) { prop.setProperty(sPassphraseKey, sPassphrase); prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); prop.store(new FileOutputStream(sProperties), null); } else { if (prop.containsKey(sPassphraseKey)) sPassphrase = prop.getProperty(sPassphraseKey); else prop.setProperty(sPassphraseKey, sPassphrase); if (prop.containsKey(sDisplaySystemTrayKey)) sDisplaySystemTray = Boolean.parseBoolean(prop.getProperty(sDisplaySystemTrayKey)); else prop.setProperty(sDisplaySystemTrayKey, Boolean.toString(sDisplaySystemTray)); if (prop.containsKey(sDebuggingKey)) sDebugging = Boolean.parseBoolean(prop.getProperty(sDebuggingKey)); else prop.setProperty(sDebuggingKey, Boolean.toString(sDebugging)); } } catch (FileNotFoundException e) { writeLog("prop load: " + e.getMessage()); } catch (IOException e) { writeLog("prop load: " + e.getMessage()); } if (sLogFileHandler != null) { sLogger = Logger.getLogger("TapLock"); sLogger.setUseParentHandlers(false); sLogger.addHandler(sLogFileHandler); SimpleFormatter sf = new SimpleFormatter(); sLogFileHandler.setFormatter(sf); writeLog("service starting"); } if (sDisplaySystemTray && SystemTray.isSupported()) { final SystemTray systemTray = SystemTray.getSystemTray(); Image trayIconImg = Toolkit.getDefaultToolkit() .getImage(TapLockServer.class.getResource("/systemtrayicon.png")); final TrayIcon trayIcon = new TrayIcon(trayIconImg, "Tap Lock"); trayIcon.setImageAutoSize(true); PopupMenu popupMenu = new PopupMenu(); MenuItem aboutItem = new MenuItem("About"); CheckboxMenuItem toggleSystemTrayIcon = new CheckboxMenuItem("Display Icon in System Tray"); toggleSystemTrayIcon.setState(sDisplaySystemTray); CheckboxMenuItem toggleDebugging = new CheckboxMenuItem("Debugging"); toggleDebugging.setState(sDebugging); MenuItem shutdownItem = new MenuItem("Shutdown Tap Lock Server"); popupMenu.add(aboutItem); popupMenu.add(toggleSystemTrayIcon); if (OS == OS_WIN) { MenuItem setPasswordItem = new MenuItem("Set password"); popupMenu.add(setPasswordItem); setPasswordItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel panel = new JPanel(); JLabel label = new JLabel("Enter your Windows account password:"); JPasswordField passField = new JPasswordField(32); panel.add(label); panel.add(passField); String[] options = new String[] { "OK", "Cancel" }; int option = JOptionPane.showOptionDialog(null, panel, "Tap Lock", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (option == 0) { String password = encryptString(new String(passField.getPassword())); if (password != null) { Properties prop = new Properties(); try { prop.load(new FileInputStream(sProperties)); prop.setProperty(sPasswordKey, password); prop.store(new FileOutputStream(sProperties), null); } catch (FileNotFoundException e1) { writeLog("prop load: " + e1.getMessage()); } catch (IOException e1) { writeLog("prop load: " + e1.getMessage()); } } } } }); } popupMenu.add(toggleDebugging); popupMenu.add(shutdownItem); trayIcon.setPopupMenu(popupMenu); try { systemTray.add(trayIcon); } catch (AWTException e) { writeLog("systemTray.add: " + e.getMessage()); } aboutItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String newline = System.getProperty("line.separator"); newline += newline; JOptionPane.showMessageDialog(null, "Tap Lock" + newline + "Copyright (c) 2012 Bryan Emmanuel" + newline + "This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version." + newline + "This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details." + newline + "You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>." + newline + "Bryan Emmanuel piusvelte@gmail.com"); } }); toggleSystemTrayIcon.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setTrayIconDisplay(e.getStateChange() == ItemEvent.SELECTED); if (!sDisplaySystemTray) systemTray.remove(trayIcon); } }); toggleDebugging.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { setDebugging(e.getStateChange() == ItemEvent.SELECTED); } }); shutdownItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { shutdown(); } }); } synchronized (sConnectionThreadLock) { (sConnectionThread = new ConnectionThread()).start(); } }
From source file:mysynopsis.FTPUploader.java
public static void display() throws IOException { JTextField address = new JTextField(server); JTextField username = new JTextField(user); JPasswordField password = new JPasswordField(pass); JTextField directory = new JTextField(dir); JPanel panel = new JPanel(new GridLayout(10, 1)); panel.add(new JLabel("Server Address:")); panel.add(address);/* w w w. java 2s . c o m*/ panel.add(new JLabel("Username:")); panel.add(username); panel.add(new JLabel("Password:")); panel.add(password); panel.add(new JLabel("Upload Directory:")); panel.add(directory); int result; /*JOptionPane pane = new JOptionPane(panel,JOptionPane.PLAIN_MESSAGE, JOptionPane.YES_NO_CANCEL_OPTION); JDialog dialog = pane.createDialog(MotherFrame.mframe, "FTP Upload Wizard - My Synopsis"); dialog.setSize(new Dimension(300,300)); dialog.setVisible(true);*/ result = JOptionPane.showConfirmDialog(MotherFrame.mframe, panel, "FTP Upload Wizard", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (result == JOptionPane.OK_OPTION) { server = address.getText(); user = username.getText(); pass = new String(password.getPassword()); // System.out.println(pass); dir = directory.getText(); JOptionPane.showMessageDialog(MotherFrame.mframe, "Press OK to start FTP Upload"); HTMLWriter.writeHTML(); JOptionPane.showMessageDialog(MotherFrame.mframe, uploadWizard()); } else { // System.out.println("Cancelled"); } }
From source file:de.mycrobase.jcloudapp.Main.java
private static Map<String, String> showLoginDialog() { String message = ""; //"Welcome to JCloudApp!"; JTextField usernameField = new JTextField(); JPasswordField passwordField = new JPasswordField(); JCheckBox remeberCheck = new JCheckBox("Remember login (on disk)"); remeberCheck.setSelected(true);/*from w ww. ja v a2s . c o m*/ Object[] content = { message, "Username:", usernameField, "Password:", passwordField, remeberCheck }; // int res = JOptionPane.showOptionDialog( // null, content, "JCloudApp - Login", // JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, icon, // null, usernameField); int res = JOptionPane.showConfirmDialog(null, content, "JCloudApp - Login", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, IconLarge); if (res == JOptionPane.OK_OPTION) { HashMap<String, String> m = new HashMap<String, String>(); m.put("username", usernameField.getText()); m.put("password", new String(passwordField.getPassword())); m.put("remember", Boolean.toString(remeberCheck.isSelected())); return m; } else { return null; } }