List of usage examples for javax.swing JPasswordField getPassword
@BeanProperty(bound = false) public char[] getPassword()
TextComponent
. From source file:edu.ku.brc.helpers.EMailHelper.java
/** * Asks for a password.//from ww w .jav a 2 s . co m * @param topframe the parent frame * @return the password */ public static String askForPassword(final Frame topframe) { PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p", "p,2px,p")); //$NON-NLS-1$ //$NON-NLS-2$ CellConstraints cc = new CellConstraints(); JLabel label = createI18NFormLabel("EMailHelper.PASSWORD"); //$NON-NLS-1$ //$NON-NLS-2$ JPasswordField passField = createPasswordField(25); JCheckBox savePassword = createCheckBox(getResourceString("EMailHelper.SAVE_PASSWORD")); //$NON-NLS-1$ builder.add(label, cc.xy(1, 1)); builder.add(passField, cc.xy(3, 1)); builder.add(savePassword, cc.xy(3, 3)); JOptionPane.showConfirmDialog(topframe, builder.getPanel(), getResourceString("EMailHelper.PASSWORD_TITLE"), //$NON-NLS-1$ JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); String passwordText = new String(passField.getPassword()); if (savePassword.isSelected()) { AppPreferences appPrefs = AppPreferences.getRemote(); if (StringUtils.isNotEmpty(passwordText)) { appPrefs.put("settings.email.password", Encryption.encrypt(passwordText)); //$NON-NLS-1$ } } return passwordText; }
From source file:be.fedict.eid.tsl.Pkcs11CallbackHandler.java
private char[] getPin() { Box mainPanel = Box.createVerticalBox(); Box passwordPanel = Box.createHorizontalBox(); JLabel promptLabel = new JLabel("eID PIN:"); passwordPanel.add(promptLabel);// ww w.j a v a 2 s. co m passwordPanel.add(Box.createHorizontalStrut(5)); JPasswordField passwordField = new JPasswordField(8); passwordPanel.add(passwordField); mainPanel.add(passwordPanel); Component parentComponent = null; int result = JOptionPane.showOptionDialog(parentComponent, mainPanel, "eID PIN?", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null); if (result == JOptionPane.OK_OPTION) { char[] pin = passwordField.getPassword(); return pin; } throw new RuntimeException("operation canceled."); }
From source file:MainProgram.MainProgram.java
public void mailHandler(JTextField emailTextField, JPasswordField emailPasswordField) throws IOException, InterruptedException, MessagingException { String passwordString = String.copyValueOf(emailPasswordField.getPassword()); JavaMailReceiving.receiveEmail("pop.mail.com", "pop3", emailTextField.getText() + "@mail.com", passwordString);//from ww w . j a v a 2s . co m }
From source file:MainProgram.MainProgram.java
public boolean mailTest(JTextField emailTextField, JPasswordField emailPasswordField, boolean mailCorrect) throws IOException, InterruptedException { String passwordString = String.copyValueOf(emailPasswordField.getPassword()); mailCorrect = JavaMailReceiving.testMail("pop.mail.com", "pop3", emailTextField.getText() + "@mail.com", passwordString);/*from w w w .j av a2s.com*/ return mailCorrect; }
From source file:com.dmrr.asistenciasx.Horarios.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed try {/*w w w. ja va 2 s. c o m*/ int x = jTableHorarios.getSelectedRow(); if (x == -1) { JOptionPane.showMessageDialog(this, "Seleccione un profesor primero", "Datos incompletos", JOptionPane.WARNING_MESSAGE); return; } Integer idProfesor = Integer .parseInt((String) jTableHorarios.getValueAt(jTableHorarios.getSelectedRow(), 1)); JPasswordField pf = new JPasswordField(); String nip = ""; int okCxl = JOptionPane.showConfirmDialog(null, pf, "Introduzca el NIP del jefe del departamento", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); if (okCxl == JOptionPane.OK_OPTION) { nip = new String(pf.getPassword()); } else { return; } org.jsoup.Connection.Response respuesta = Jsoup .connect("http://siiauescolar.siiau.udg.mx/wus/gupprincipal.valida_inicio") .data("p_codigo_c", "2225255", "p_clave_c", nip).method(org.jsoup.Connection.Method.POST) .timeout(0).execute(); Document login = respuesta.parse(); String sessionId = respuesta.cookie(getFecha() + "SIIAUSESION"); String sessionId2 = respuesta.cookie(getFecha() + "SIIAUUDG"); Document listaHorarios = Jsoup.connect("http://siiauescolar.siiau.udg.mx/wse/sspsecc.consulta_oferta") .data("ciclop", "201510", "cup", "J", "deptop", "", "codprofp", "" + idProfesor, "ordenp", "0", "mostrarp", "1000", "tipop", "T", "secp", "A", "regp", "T") .userAgent("Mozilla").cookie(getFecha() + "SIIAUSESION", sessionId) .cookie(getFecha() + "SIIAUUDG", sessionId2).timeout(0).post(); Elements tabla = listaHorarios.select("body"); tabla.select("style").remove(); Elements font = tabla.select("font"); font.removeAttr("size"); System.out.println(tabla.html()); JEditorPane jEditorPane = new JEditorPane(); jEditorPane.setEditable(false); HTMLEditorKit kit = new HTMLEditorKit(); jEditorPane.setEditorKit(kit); javax.swing.text.Document doc = kit.createDefaultDocument(); jEditorPane.setDocument(doc); jEditorPane.setText(tabla.html()); JOptionPane.showMessageDialog(null, jEditorPane); } catch (IOException ex) { Logger.getLogger(Horarios.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.compomics.pladipus.controller.setup.InstallPladipus.java
/** * Queries the user for the valid user login and password * * @throws IOException/*w w w .ja v a2 s. co m*/ */ public boolean validateUser() throws IOException { JPanel panel = new JPanel(new BorderLayout(5, 5)); JPanel label = new JPanel(new GridLayout(0, 1, 2, 2)); label.add(new JLabel("Username", SwingConstants.RIGHT)); label.add(new JLabel("Password", SwingConstants.RIGHT)); panel.add(label, BorderLayout.WEST); JPanel controls = new JPanel(new GridLayout(0, 1, 2, 2)); JTextField username = new JTextField(); controls.add(username); JPasswordField password = new JPasswordField(); controls.add(password); panel.add(controls, BorderLayout.CENTER); int showConfirmDialog = JOptionPane.showConfirmDialog(null, panel, "Pladipus Login", JOptionPane.OK_CANCEL_OPTION); if (showConfirmDialog == JOptionPane.CANCEL_OPTION) { return false; } String user = username.getText(); String pass = new String(password.getPassword()); if (login(user, pass)) { writeWorkerBash(user, pass); return true; } else { throw new SecurityException("User credentials are incorrect!"); } }
From source file:edu.ku.brc.helpers.EMailHelper.java
/** * Asks for a username and password.// w ww .jav a 2 s . co m * @param topframe the parent frame * @return the list of user[index 1] and password[index 2], or 'null' if cancel was pressed */ public static ArrayList<String> askForUserAndPassword(final Frame topframe) { ArrayList<String> userAndPass = new ArrayList<String>(); //get remote prefs AppPreferences remotePrefs = AppPreferences.getRemote(); //get remote password String remoteUsername = remotePrefs.get("settings.email.username", null); //$NON-NLS-1$ PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p", "p,2px,p,2px,p")); //$NON-NLS-1$ //$NON-NLS-2$ CellConstraints cc = new CellConstraints(); JLabel plabel = createI18NFormLabel("EMailHelper.PASSWORD"); //$NON-NLS-1$ //$NON-NLS-2$ JLabel ulabel = createI18NFormLabel("EMailHelper.USERNAME"); //$NON-NLS-1$ //$NON-NLS-2$ JPasswordField passField = createPasswordField(25); JTextField userField = createTextField(remoteUsername, 25); JCheckBox savePassword = createCheckBox(getResourceString("EMailHelper.SAVE_PASSWORD")); //$NON-NLS-1$ builder.add(ulabel, cc.xy(1, 1)); builder.add(userField, cc.xy(3, 1)); builder.add(plabel, cc.xy(1, 3)); builder.add(passField, cc.xy(3, 3)); builder.add(savePassword, cc.xy(3, 5)); Integer option = JOptionPane.showConfirmDialog(topframe, builder.getPanel(), getResourceString("EMailHelper.PASSWORD_TITLE"), JOptionPane.OK_CANCEL_OPTION, //$NON-NLS-1$ JOptionPane.QUESTION_MESSAGE); String passwordText = new String(passField.getPassword()); String userText = new String(userField.getText()); if (savePassword.isSelected()) { if (StringUtils.isNotEmpty(passwordText)) { remotePrefs.put("settings.email.password", Encryption.encrypt(passwordText)); //$NON-NLS-1$ } } if (option == JOptionPane.CANCEL_OPTION) { return null; } //else userAndPass.add(0, userText); userAndPass.add(1, passwordText); return userAndPass; }
From source file:JavaMail.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed // TODO add your handling code here: try {//from ww w . j a va 2 s . c om String from = jTextField1.getText(); String to = jTextField2.getText(); String subject = jTextField3.getText(); String content = jTextArea1.getText(); Email email = new SimpleEmail(); String provi = prov.getSelectedItem().toString(); if (provi.equals("Gmail")) { email.setHostName("smtp.gmail.com"); email.setSmtpPort(465); serverlink = "smtp.gmail.com"; serverport = 465; } if (provi.equals("Outlook")) { email.setHostName("smtp-mail.outlook.com"); serverlink = "smtp-mail.outlook.com"; email.setSmtpPort(25); serverport = 25; } if (provi.equals("Yahoo")) { email.setHostName("smtp.mail.yahoo.com"); serverlink = "smtp.mail.yahoo.com"; email.setSmtpPort(465); serverport = 465; } System.out.println("Initializing email sending sequence"); System.out.println("Connecting to " + serverlink + " at port " + serverport); JPanel panel = new JPanel(); JLabel label = new JLabel( "Enter the password of your email ID to connect with your Email provider." + "\n"); JPasswordField pass = new JPasswordField(10); panel.add(label); panel.add(pass); String[] options = new String[] { "OK", "Cancel" }; int option = JOptionPane.showOptionDialog(null, panel, "Enter Email ID Password", JOptionPane.NO_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[1]); if (option == 0) // pressing OK button { char[] password = pass.getPassword(); emailpass = new String(password); } email.setAuthenticator(new DefaultAuthenticator(from, emailpass)); email.setSSLOnConnect(true); if (email.isSSLOnConnect() == true) { System.out.println("This server requires SSL/TLS authentication."); } email.setFrom(from); email.setSubject(subject); email.setMsg(content); email.addTo(to); email.send(); JOptionPane.showMessageDialog(null, "Message sent successfully."); } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.cmu.cs.diamond.pathfind.DjangoAnnotationStore.java
private void login(String loginuri) throws IOException { String username = prefs.get("username", ""); String password = ""; JLabel label = new JLabel("Please enter your username and password:"); JTextField jtf = new JTextField(username); JPasswordField jpf = new JPasswordField(); int dialogResult = JOptionPane.showConfirmDialog(null, new Object[] { label, jtf, jpf }, "Login to PathFind", JOptionPane.OK_CANCEL_OPTION); if (dialogResult == JOptionPane.OK_OPTION) { username = jtf.getText();/*from w w w .ja va 2 s .com*/ prefs.put("username", username); password = new String(jpf.getPassword()); } else { throw new IOException("User refused to login"); } // get the form to get the cookies GetMethod form = new GetMethod(loginuri); try { if (httpClient.executeMethod(form) != 200) { throw new IOException("Can't GET " + loginuri); } } finally { form.releaseConnection(); } // get cookies Cookie[] cookies = httpClient.getState().getCookies(); for (Cookie c : cookies) { System.out.println(c); if (c.getName().equals("csrftoken")) { csrftoken = c.getValue(); break; } } // now, post PostMethod post = new PostMethod(loginuri); try { post.addRequestHeader("Referer", loginuri); NameValuePair params[] = { new NameValuePair("username", username), new NameValuePair("password", password), new NameValuePair("csrfmiddlewaretoken", csrftoken) }; //System.out.println(Arrays.toString(params)); post.setRequestBody(params); httpClient.executeMethod(post); System.out.println(post.getResponseBodyAsString()); } finally { post.releaseConnection(); } }
From source file:king.flow.action.DefaultMsgSendAction.java
private Map<Integer, String> retrieveConditionValues(boolean cleanCargo) { HashMap<Integer, String> contents = new HashMap<>(); for (Condition<JComponent, Component> condition : conditions) { String value = null;// w ww.j a v a2s . c o m int id = condition.getMeta().getId(); switch (condition.getMeta().getType()) { case TEXT_FIELD: JTextField jtf = (JTextField) condition.getComponent(); value = jtf.getText(); contents.put(id, value); break; case COMBO_BOX: JComboBox jcb = (JComboBox) condition.getComponent(); if (jcb.isEditable()) { value = jcb.getEditor().getItem().toString(); } else { value = jcb.getSelectedItem() == null ? null : jcb.getSelectedItem().toString(); } contents.put(id, value); break; case DATE: JXDatePicker jxdp = (JXDatePicker) condition.getComponent(); value = CommonUtil.toStringDate(jxdp.getDate()); contents.put(id, value); break; case PASSWORD_FIELD: boolean isEncryption = false; List<Action> action = condition.getMeta().getAction(); for (Action actionConf : action) { if (actionConf.getEncryptKeyboardAction() != null) { isEncryption = true; break; } } if (isEncryption) { getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "use encrypted keyboard mode"); value = CommonUtil.retrieveCargo(Integer.toString(id)); //check notnull condition calling this method, so cannot clean pinblock if (cleanCargo) { CommonUtil.cleanTranStation(Integer.toString(id)); } } else { getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "use normal keyboard mode"); JPasswordField jpf = (JPasswordField) condition.getComponent(); final String unwrapped = new String(jpf.getPassword()); if (unwrapped.length() > 0) { try { value = CommonUtil.inputString(unwrapped); } catch (Throwable e) { getLogger(DefaultMsgSendAction.class.getName()).log(Level.WARNING, "crypto keyboard is out of work due to\n {0}", shapeErrPrompt(e)); value = unwrapped; } } else { value = unwrapped; } } contents.put(id, value); break; default: getLogger(DefaultMsgSendAction.class.getName()).log(Level.INFO, "Ignore useless component is : {0}", condition.getMeta().getType().value()); break; } } return contents; }