Hello.This is an authentication service.How to use it? Create a new class of your project, called Authenticator.Copy there this and save it.Then open your first class, where is your main program.Then just write "extends Authenticator" after your class name.Enjoy :).
import java.io.*;
import java.util.*;
public class Authenticator implements Runnable{
public Thread thread;
public Random random;
public BufferedReader reader;
public int number;
public String read0;
public int read;
Authenticator(){
thread = new Thread();
thread.start();
random = new Random();
reader = new BufferedReader(new InputStreamReader(System.in));
number = random.nextInt(999999999);
try{
System.out.println("Generated code is: " + number);
System.out.print("Please, insert generated code: ");
read0 = reader.readLine();
read = Integer.parseInt(read0);
}
catch(IOException v){
System.out.println("Error " + v);
}
try{
System.out.println('\n' + "Checking...");
Thread.sleep(5000);
System.out.println("Confirming...");
Thread.sleep(3000);
System.out.println("Done!");
}
catch(InterruptedException v){
System.out.println("Error " + v);
}
if(read == number){
System.out.println('\n' + "Authentication succesful!");
}
else{
System.out.println('\n' + "Authentication has not been succesful.");
System.exit(0);
}
}
@Override
public void run() {
// TODO Auto-generated method stub
}
public static void main(String args[])throws IOException{
new Authenticator();
}
}
Comments