Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Remote Method InvocationRSS Feeds

RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client..

Posted By: Milind Mishra     Category: Java     Views: 7006

Develop an RMI based application for login validation based on data saved
in text file stored on the server and will display appropriate message to
the client side depending on the success or failure of login.

Code for RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client.. in Java

// LoginRmi Interfacepublicinterface LoginRMI extends java.rmi.Remote
{
    int checklogin(String loginname) throws java.rmi.RemoteException,Exception;
    int checkpassword(String loginname,String password) throws java.rmi.RemoteException,Exception;
}


// LoginRMIImpl.java, LoginRMI implementation

import java.rmi.*;
import java.rmi.server.UnicastRemoteObject;
import java.io.*;

publicclass LoginRMIImpl extends UnicastRemoteObject implements LoginRMI
{
    private FileReader fr;
    private BufferedReader br;
    String s,s1,s2;
    int index,retval;
  public LoginRMIImpl(String name) throws RemoteException
  {
    super();
    try
    {
      Naming.rebind(name, this);
    } catch (Exception e)
    { System.out.println("Exception: " + e.getMessage());
      e.printStackTrace();
    }
  }

  publicint checklogin(String loginname) throws RemoteException,Exception
  { 
    fr = new FileReader("logindetails.txt");
    br = new BufferedReader(fr);
    retval = 0;
            
    while(( s = br.readLine())!=null && retval != 1)
    {
        index = s.indexOf(" ");
        s1 = s.substring(0,index);
        if(s1.equals(loginname))
        {
            retval = 1;
        }
        else
        {
            retval = 0;
        }
    }
    fr.close();
    return retval;
            
  }

 publicint checkpassword(String loginname,String password) throws RemoteException,Exception
  { 
    fr = new FileReader("logindetails.txt");
    br = new BufferedReader(fr);
    retval = 0;
    while((s = br.readLine())!=null && retval !=1)
    {
        index = s.indexOf(" ");
        s1 = s.substring(0,index);
        s2 = s.substring(index+1);
        if(s1.equals(loginname) && s2.equals(password))
        {
            retval = 1;
        }
        else
        {
            retval = 0;
        }
    }
    fr.close();
    return retval;
                
  }


}


// LoginRMIServer.java

import java.rmi.*;
import java.rmi.server.*;

publicclass LoginRMIServer
{

 publicstaticvoid main(String args[])
 {

   // Create and install the security manager
   System.setSecurityManager(new RMISecurityManager());

   try
   {
     // Create LoginRMIImpl
     LoginRMIImpl myLogin = new LoginRMIImpl("//Binita/myLoginRMI");
     System.out.println("LoginRMI Server ready.");
   } catch (Exception e)
   { System.out.println("Exception: " + e.getMessage());
     e.printStackTrace();
   }
 }
}


// LoginRMIClient.java  RMI Login client

import java.rmi.*;
import java.rmi.registry.*;
import java.rmi.server.*;
import java.lang.*;
import java.io.*;

publicclass LoginRMIClient
{ 
  publicstaticvoid main(String args[])
  { 
    // Create and install the security manager
    System.setSecurityManager(new RMISecurityManager());
    int status=0;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String name,name1;
    try
    { 
    LoginRMI myLogin = (LoginRMI)Naming.lookup("//"
                          + args[0] + "/" + "myLoginRMI");
    System.out.println("Enter loginname :");
    name = in.readLine();      
    status = myLogin.checklogin(name);
    
    if(status == 1)
    {
        System.out.println("Enter password:");
        name1 = in.readLine();    
        status = myLogin.checkpassword(name,name1);
        if(status == 1)
        {
            System.out.println("Successfully login.....");
        }
        else
        {
            System.out.println("You have Entered wrong password");
        }
    }
    else
    {
        System.out.println("You have entered wrong login name");
    }

    } catch(Exception e)
    { System.err.println("System Exception" + e);
    }
   System.exit(0);
  }
}


// OUTPUT

-----  logindetails.txt  ------

binita modi
rasesh patel
dipen shah
krupa parikh
--------------------


Enter loginname :
krupa
Enter password:
modi
You have Entered wrong password


Enter loginname :
binita
Enter password:
modi
Successfully login.....


Enter loginname :
nauka
You have entered wrong login name
  
Share: 



Milind Mishra
Milind Mishra author of RMI based application for login validation based on data saved in text file stored on the server and will display appropriate message to the client.. is from India.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!