NoNameCracksInc

Java Authenticator

Apr 3rd, 2013
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. 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 :).
  2.  
  3. import java.io.*;
  4. import java.util.*;
  5.  
  6. public class Authenticator implements Runnable{
  7. public Thread thread;
  8. public Random random;
  9. public BufferedReader reader;
  10. public int number;
  11. public String read0;
  12. public int read;
  13.  
  14. Authenticator(){
  15. thread = new Thread();
  16. thread.start();
  17. random = new Random();
  18. reader = new BufferedReader(new InputStreamReader(System.in));
  19.  
  20. number = random.nextInt(999999999);
  21.  
  22. try{
  23. System.out.println("Generated code is: " + number);
  24. System.out.print("Please, insert generated code: ");
  25. read0 = reader.readLine();
  26. read = Integer.parseInt(read0);
  27. }
  28. catch(IOException v){
  29. System.out.println("Error " + v);
  30. }
  31.  
  32. try{
  33. System.out.println('\n' + "Checking...");
  34. Thread.sleep(5000);
  35. System.out.println("Confirming...");
  36. Thread.sleep(3000);
  37. System.out.println("Done!");
  38. }
  39. catch(InterruptedException v){
  40. System.out.println("Error " + v);
  41. }
  42.  
  43. if(read == number){
  44. System.out.println('\n' + "Authentication succesful!");
  45. }
  46. else{
  47. System.out.println('\n' + "Authentication has not been succesful.");
  48. System.exit(0);
  49. }
  50. }
  51. @Override
  52. public void run() {
  53. // TODO Auto-generated method stub
  54. }
  55. public static void main(String args[])throws IOException{
  56. new Authenticator();
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment