1. An authentication server is an application that facilitates the authenticatio
ID: 3548172 • Letter: 1
Question
1. An authentication server is an application that facilitates the authentication process of any client who attempts to access a network. It stores the usernames and passwords that identify the clients logging in. Accordingly, when a potential client accesses the authentication server, a username and password will be the identifying data required.
In this homework, you are required to develop a multithreaded TCP server/client authentication application with the following specifications:
? The server should have a predefined list of clients
Explanation / Answer
I wrote this program and dont know whether it is upto your expectations or not. But, I am providing you the program along with its tested output as follows:
Client Program
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
import java.io.*;
import java.net.*;
class Client_1
{
public static void main(String ar[])throws Exception
{
Socket s=new Socket(InetAddress.getLocalHost(),10000);
PrintStream ps=new PrintStream(s.getOutputStream());
System.out.println("Enter the Username :");
DataInputStream uname=new DataInputStream(System.in);
String sUNAME=uname.readLine();
System.out.println("enter the password :");
DataInputStream pswd=new DataInputStream(System.in);
String sPSWD=pswd.readLine();
ps.println(sUNAME);
ps.println(sPSWD);
DataInputStream dis1=new DataInputStream(s.getInputStream());
System.out.println("password status: "+dis1.readLine());
DataInputStream spin=new DataInputStream(s.getInputStream());
int key=Integer.parseInt(spin.readLine());
key=key^1111111111;
ps.println(key);
DataInputStream dis2=new DataInputStream(s.getInputStream());
System.out.println("pin status: "+dis2.readLine());
}
}
Server Program
import java.io.*;
import java.net.*;
class Server_1
{
public static int key = (int)(Math.random()*1000000000);
public static String user = new String("MITCOE");
public static String password = new String("MIT");
public static void main(String ar[])throws Exception
{
ServerSocket ss=new ServerSocket(10000);
Socket s=ss.accept();
DataInputStream inputFrmClient=new DataInputStream(s.getInputStream());
String sUNAME=inputFrmClient.readLine();//Receive User name frm client
String sPSWD=inputFrmClient.readLine();// Receive Password frm client
PrintStream ps=new PrintStream(s.getOutputStream());
if (user.equals(sUNAME) && password.equals(sPSWD))
{
ps.println("Password Success.");
}
else
{
ps.println("Password Failed.");
}
ps.println(key);//Sending the Challange
int n=Integer.parseInt(inputFrmClient.readLine());//Receive eX-Ored key
n=n^1111111111;
if ((user.equals(sUNAME)) && n == key)
{
ps.println("key Success.");
}
else
{
ps.println("key Failed.");
}
}
}
OUTPUT
run:
Enter the Username :MITCOE
enter the password :MIT
password status: Password Success.
pin status: key Success.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.