Fundamental program for creation & checking of account 3

First file should be compiled first…..then second & third.
User Id & Password will be stored temporarily as object of UserBean class.

The object of above class will be saved in usermast.dat file as the object of the above class has been serialized . The saving process will be done by the second file that is UserEntry .

The third file that is UserValid will check the valid userid & password . If any non valid userid or password is given to check it will print Invalid User.

After compilation of all the java source files the UserEntry class should be run first than for checking the valid userid & password the UserValid class should be run.

//***********First Source file*************//
import java.io.Serializable;

public class UserBean implements Serializable
{
private String login;
private String password;
public UserBean()
{
super();
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public boolean userCheck(UserBean u)
{
boolean bool=false;
if(this.password.equals(u.getPassword()) && this.login.equals(u.getLogin()))
bool=true;
return bool;
}

}

//***********Second Source file*************//

import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectOutputStream;

public class UserEntry
{

public static void main(String[] args) throws IOException
{
FileOutputStream f1=new FileOutputStream(“C:\\usermast.dat”,true);/*user Id & password will be saved in this usermast.dat file*/
ObjectOutputStream os1=new ObjectOutputStream(f1);
UserBean [] ub=new UserBean[3];
for(int i=0;i<3;i++) { ub[i]=new UserBean(); BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nEnter User name: "); ub[i].setLogin(br.readLine()); System.out.print("\nEnter User Password: "); ub[i].setPassword(br.readLine()); os1.writeObject(ub[i]);os1.flush(); } os1.close(); f1.close(); } } //***********Third source file***************// import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.ObjectInputStream; public class UserValid { public static void main(String[] args) throws IOException,ClassNotFoundException { UserBean [] ub=new UserBean[5]; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); System.out.print("\nEnter User Name:"); String unm=br.readLine(); System.out.print("\nEnter Password:"); String psd=br.readLine(); UserBean u=new UserBean(); u.setLogin(unm); u.setPassword(psd); FileInputStream f2=new FileInputStream("C:\\usermast.dat"); ObjectInputStream os2=new ObjectInputStream(f2); boolean b=false; for(int i=0;i<3;i++) { ub[i]=(UserBean)os2.readObject(); b=u.userCheck(ub[i]); if(b) { System.out.print("\nValid User"); break; } } if(!b) System.out.print("\nInvalid User"); os2.close(); f2.close(); } }