Advertisement
Guest User

Untitled

a guest
Feb 11th, 2019
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1.  
  2. package taskperf6;
  3. import java.io.BufferedReader;
  4. import java.io.BufferedWriter;
  5. import java.io.File;
  6. import java.io.FileNotFoundException;
  7. import java.io.FileReader;
  8. import java.io.FileWriter;
  9. import java.io.IOException;
  10. import java.util.Scanner;
  11.  
  12. public class TaskPerf6 {
  13.  
  14. public static void main(String[] args)throws FileNotFoundException, IOException{
  15. Scanner input = new Scanner(System.in);
  16. System.out.println("1.Registration");
  17. System.out.println("2.Log in");
  18. System.out.print("Select Option: ");
  19. int select = input.nextInt();
  20.  
  21. switch(select){
  22. case 1:
  23. String username;
  24. String pass;
  25. String strl = input.nextLine();
  26. BufferedWriter writer = new BufferedWriter(new FileWriter("C:/records.txt"));
  27. System.out.print("Enter Username: ");
  28. username = input.nextLine();
  29. writer.write(username);
  30. writer.newLine();
  31. System.out.print("Enter Password: ");
  32. pass = input.nextLine();
  33. writer.write(pass);
  34. writer.close();
  35. System.out.println("Successfully Registered");
  36. System.out.print("Do You Want to Log in Now[Y/N]:");
  37. String YesNo = input.nextLine();
  38. if(YesNo.equalsIgnoreCase("Y")){
  39. File file = new File("C:/records.txt");
  40. FileReader fr = new FileReader(file);
  41. BufferedReader br = new BufferedReader(fr);
  42. String username1;
  43. String pass1;
  44. String strl1 = input.nextLine();
  45. System.out.print("Enter Your Username: ");
  46. username1 = input.nextLine();
  47. System.out.print("Enter Your Password: ");
  48. pass1 = input.nextLine();
  49.  
  50. String s = null;
  51. String[] registeredAccount = new String[2];
  52. int ctr = 0;
  53.  
  54. while((s = br.readLine()) != null){
  55. registeredAccount[ctr] = s;
  56. ctr++;
  57. }
  58.  
  59. if(username1.equalsIgnoreCase(registeredAccount[0]) && pass1.equalsIgnoreCase(registeredAccount[1])){
  60. System.out.print("Successfully Logged in");
  61. }
  62.  
  63. else{
  64. System.out.print("Incorrect Username or Password");
  65. }
  66. }
  67.  
  68. else if(YesNo.equalsIgnoreCase("N")){
  69. System.out.print("End of Program");
  70. }
  71. break;
  72.  
  73. case 2:
  74. File file = new File("C:/records.txt");
  75. FileReader fr = new FileReader(file);
  76. BufferedReader br = new BufferedReader(fr);
  77. String username1;
  78. String pass1;
  79. String strl1 = input.nextLine();
  80. System.out.print("Enter Your Username: ");
  81. username1 = input.nextLine();
  82. System.out.print("Enter Your Password: ");
  83. pass1 = input.nextLine();
  84.  
  85. String s = null;
  86. String[] registeredAccount = new String[2];
  87. int ctr = 0;
  88.  
  89. while((s = br.readLine()) != null){
  90. registeredAccount[ctr] = s;
  91. ctr++;
  92. }
  93.  
  94. if(username1.equalsIgnoreCase(registeredAccount[0]) && pass1.equalsIgnoreCase(registeredAccount[1])){
  95. System.out.print("Successfully Logged in");
  96. }
  97.  
  98. else{
  99. System.out.print("Incorrect Username or Password");
  100. }
  101.  
  102.  
  103. }
  104. }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement