////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //PIMS: Personal Invstment Management System //Class : ChangePassword //This class displays the interface fo changing the password and also registers //the new password. To change the password the user needs to enter the //previous password. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; import java.lang.*; import java.io.*; import java.util.*; public class ChangePassword extends JFrame implements ActionListener{ private SecurityManager SM; private String login; private String password; private int chances = 0; Label passl; TextField pass; Label new_passl; TextField new_pass; Label retype_passl; TextField retype_pass; Button ok; Button cancel; public ChangePassword(SecurityManager SM){ this.SM = SM; login = ""; password = ""; changepass(); } private void changepass(){ setSize(400, 200); setLocation(120,150); setBackground(Color.white); setTitle("PIMS Change Password"); Container CP = getContentPane(); CP.setBackground(Color.white); CP.setLayout(new GridLayout(4,1)); Panel pan1 = new Panel(); Panel pan2 = new Panel(); Panel pan3 = new Panel(); Panel pan4 =new Panel(); passl = new Label("Old Password"); pass = new TextField(15); pass.setEchoChar('*'); pan1.add(passl);pan1.add(pass); new_passl = new Label("New Password"); new_pass = new TextField(15); new_pass.setEchoChar('*'); pan2.add(new_passl);pan2.add(new_pass); retype_passl = new Label("Retype New Password"); retype_pass = new TextField(15); retype_pass.setEchoChar('*'); pan3.add(retype_passl);pan3.add(retype_pass); ok = new Button("Ok"); ok.addActionListener(this); cancel = new Button("Cancel"); cancel.addActionListener(this); pan4.add(ok);pan4.add(cancel); CP.add(pan1); CP.add(pan2); CP.add(pan3); CP.add(pan4); setVisible(true); } public void actionPerformed(ActionEvent ae){ try{ String action = ae.getActionCommand(); String passt = pass.getText(); String new_passt = new_pass.getText(); String retype_passt = retype_pass.getText(); if(action.equals("Ok")){ if(passt.equals("") || new_passt.equals("") || retype_passt.equals("")){ Error e = new Error("Login or Password not Entered."); return; } if(SM.ValidateUser(passt)){ if(!new_passt.equals(retype_passt)){ new Error("typed passwords do not match"); setVisible(false); } else{ SM.ChangePassword(new_passt); new Message("Your PIMS Password has been Changed"); setVisible(false); } } else{ new Error("PIMS Authentication Failed"); } } if(action.equals("Cancel"))setVisible(false); }catch(Exception e){ new Error("Problem in changing password"); return; } } }