1 package SnowMailClient.view.dialogs; 2 3 import SnowMailClient.MailEngine.*; 4 import SnowMailClient.model.*; 5 import SnowMailClient.model.accounts.*; 6 import SnowMailClient.crypto.Utilities; 7 import SnowMailClient.*; 8 import SnowMailClient.Language.Language; 9 import snow.utils.gui.*; 10 11 12 import java.awt.*; 13 import java.util.Arrays ; 14 import java.awt.event.*; 15 import javax.swing.*; 16 import javax.swing.border.*; 17 18 public class ChangePasswordDialog extends JDialog { 19 20 private final JPasswordField pass = new JPasswordField(); 21 private final JPasswordField newPass = new JPasswordField(); 22 private final JPasswordField confirmNewPass = new JPasswordField(); 23 public boolean doHash = false; 25 private final MailAccount ma; 26 27 public final int fontSize = UIManager.getFont("Label.font").getSize(); 28 29 30 public ChangePasswordDialog(MailAccount _ma, JDialog owner) 31 { 32 super(owner, true); 33 this.ma = _ma; 34 setTitle(Language.translate("Change Account Password for %",ma.getAddress())); 35 36 getContentPane().setLayout(new BorderLayout()); 37 38 JPanel cpanel = new JPanel(); 39 GridLayout3 gl = new GridLayout3(2, cpanel); 40 41 42 cpanel.setBorder(new EmptyBorder(fontSize/2,fontSize/2,fontSize/2,fontSize/2)); 43 getContentPane().add(cpanel, BorderLayout.CENTER); 44 gl.add(new JLabel(Language.translate("New password")), false); 45 gl.add(newPass, true); 46 gl.add(new JLabel(Language.translate("Confirm")), false); 47 gl.add(confirmNewPass, true); 48 49 JPanel contrlpanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); 50 getContentPane().add(contrlpanel, BorderLayout.SOUTH); 51 52 JButton cancel = new JButton(Language.translate("Cancel")); 53 contrlpanel.add(cancel); 54 cancel.addActionListener(new ActionListener( ){ 55 public void actionPerformed(ActionEvent e) 56 { 57 dispose(); 58 } 59 }); 60 61 JButton changePass = new JButton(Language.translate("Change Password")); 62 changePass.setBackground(Color.orange); 63 contrlpanel.add(changePass); 64 final JDialog ref = this; 65 changePass.addActionListener(new ActionListener( ){ 66 public void actionPerformed(ActionEvent e) 67 { 68 if(!Arrays.equals(newPass.getPassword(), confirmNewPass.getPassword())) 70 { 71 JOptionPane.showMessageDialog(ref, Language.translate("ERROR : Bad confirmation")); 73 } 74 else 75 { 76 try 77 { 78 SecurePopConnection sp = ma.getCheckedPopConnection(); 79 sp.changePassword( getPassword() ); 80 dispose(); 82 } 83 catch(Exception ex) 84 { 85 ex.printStackTrace(); 87 JOptionPane.showMessageDialog( 88 ref, Language.translate("Secure POP connection error") 89 + ": \n"+ex.getMessage()); 90 } 92 } 93 } 94 }); 95 } 96 97 public final String getPassword() 98 { 99 String p = new String (confirmNewPass.getPassword()); 100 if(doHash) 101 return Utilities.hashPassword(p); 102 else 103 return p; 104 } 105 106 } | Popular Tags |