////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //PIMS: Personal Invstment Management System //Class : Login //This class displays the PIMS login screen. After taking the input from the //user, it calls the authenticate function of the dataRepository with the login name //as the parameter. The authenticate method of the dataRepository class returns //the password, which is crosschecked with the password entered. //If the authentication is successfull PIMS is started, else the user is //given another chance. In all the user is given 3 chances to validate. Presently //the authentication system is trivial, it does not involve any encryption. The username //and passwords are just strings. However with the given framework encryption //routines can be easily employed to get a better authentication system. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; import java.lang.*; import java.io.*; import java.util.*; public class Login extends JFrame implements ActionListener{ private SecurityManager SM; private GUI g; private String login; private String password; private int chances = 0; Label logl; TextField log; Label passl; TextField pass; Button ok; Button cancel; public Login(SecurityManager SM, GUI g){ this.SM = SM; this.g = g; login = ""; password = ""; authenticate(); } private void authenticate(){ setSize(300, 150); setLocation(320,280); setBackground(Color.white); setTitle("PIMS Authentication System"); Container CP = getContentPane(); CP.setBackground(Color.white); CP.setLayout(new GridLayout(3,1)); Panel pan1 = new Panel(); Panel pan2 = new Panel(); Panel pan3 = new Panel(); logl = new Label("Login"); log = new TextField(15); pan1.add(logl);pan1.add(log); passl = new Label("Password"); pass = new TextField(15); pass.setEchoChar('*'); pan2.add(passl);pan2.add(pass); ok = new Button("Ok"); ok.addActionListener(this); cancel = new Button("Cancel"); cancel.addActionListener(this); pan3.add(ok);pan3.add(cancel); CP.add(pan1); CP.add(pan2); CP.add(pan3); setVisible(true); } public void actionPerformed(ActionEvent ae){ try{ String action = ae.getActionCommand(); String logt = log.getText(); String passt = pass.getText(); if(action.equals("Ok")){ if(logt.equals("") || passt.equals("")){ Error e = new Error("Login or Password not Entered."); return; } if(SM.ValidateUser(logt, passt)){ setVisible(false); g.makeGUI(); } else{ Error e = new Error("Authentication Failed"); if(chances == 3)System.exit(-1); chances++; } } if(action.equals("Cancel"))System.exit(0); }catch(Exception e){} } }