FileDocCategorySizeDatePackage
MailAuthenticator.javaAPI DocExample2069Mon Oct 09 13:09:34 BST 2000None

MailAuthenticator

public class MailAuthenticator extends Authenticator

Fields Summary
private JDialog
passwordDialog
private JLabel
mainLabel
private JLabel
userLabel
private JLabel
passwordLabel
private JTextField
usernameField
private JPasswordField
passwordField
private JButton
okButton
Constructors Summary
public MailAuthenticator()

  
    
    this("");
  
public MailAuthenticator(String username)

    
    Container pane = passwordDialog.getContentPane();
    pane.setLayout(new GridLayout(4, 1));
    pane.add(mainLabel);
    JPanel p2 = new JPanel();
    p2.add(userLabel);
    p2.add(usernameField);
    usernameField.setText(username);
    pane.add(p2);
    JPanel p3 = new JPanel();
    p3.add(passwordLabel);
    p3.add(passwordField);
    pane.add(p3);
    JPanel p4 = new JPanel();
    p4.add(okButton);
    pane.add(p4);   
    passwordDialog.pack();
    
    ActionListener al = new HideDialog();
    okButton.addActionListener(al);
    usernameField.addActionListener(al);
    passwordField.addActionListener(al);
    
  
Methods Summary
public javax.mail.PasswordAuthenticationgetPasswordAuthentication()

    
    passwordDialog.show();
    
    // getPassword() returns an array of chars for security reasons.
    // We need to convert that to a String for 
    // the PasswordAuthentication() constructor.
    String password = new String(passwordField.getPassword());
    String username = usernameField.getText();
    // Erase the password in case this is used again.
    // The provider should cache the password if necessary.
    passwordField.setText("");
    return new PasswordAuthentication(username, password);