////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //PIMS: Personal Invstment Management System //Class : Security Manager //This class defines two methods:- // 1. Validate User // 2. Change Password ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// import java.lang.*; import java.io.*; import java.util.*; import java.text.*; public class SecurityManager{ //attributes. private dataRepository DR; private String login;//login name of the user in the database private String password;//password of the user in the database private boolean debug = false;//boolean variable used for debugging this class. public SecurityManager(dataRepository DR){ try{ this.DR = DR; //Read the login and password of the authorized user. String log_pass = DR.GetAuthentication(); tokenize(log_pass); }catch(Exception e){} } //private method: tokenizes : private void tokenize(String log_pass){ StringTokenizer ST = new StringTokenizer(log_pass, ":"); login = ST.nextToken(); password = ST.nextToken(); } //Method to validate user credentials entrered public boolean ValidateUser(String log, String pass ){ if(login.equals(log) && password.equals(pass))return(true); else return(false); } //Method to validate the password of the user public boolean ValidateUser(String pass){ if(password.equals(pass))return(true); else return(false); } //Method to change the password of the user. Returns true if the //pasword is changed, otherwise if there is an error public boolean ChangePassword(String new_pass)throws Exception{ password = new_pass; return(DR.changePassword(new_pass)); } }