Advertisement
Guest User

Untitled

a guest
Feb 11th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1.  
  2. package taskperformance;
  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.  
  13.  
  14. public class Taskperformance {
  15.  
  16.  
  17. public static void main(String[] args)throws FileNotFoundException, IOException {
  18. Scanner input = new Scanner (System.in);
  19. System.out.println("1.Registration");
  20. System.out.println("2.Log in");
  21. System.out.println("Select Option:");
  22. int select = input.nextInt();
  23.  
  24. switch(select){
  25. case 1:
  26. String username;
  27. String pass;
  28. String str1 = input.nextLine();
  29. BufferedWriter writer = new BufferedWriter(new FileWriter("C:/Records.txt"));
  30. System.out.println("Enter Username: ");
  31. username = input.nextLine();
  32. writer.write(username);
  33. writer.newLine();
  34. System.out.println("Enter Password:");
  35. pass = input.nextLine();
  36. writer.write(pass);
  37. writer.close();
  38. System.out.println("Successfully Registered");
  39. break;
  40.  
  41. case 2:
  42. File file = new File ("C:/Records.txt");
  43. FileReader fr = new FileReader(file);
  44. BufferedReader br = new BufferedReader(fr);
  45. String username1;
  46. String pass1;
  47. String Strl1 = input.nextLine();
  48. System.out.println("Enter Username: ");
  49. username1 = input.nextLine();
  50. System.out.println("Enter Password:");
  51. pass1 = input.nextLine();
  52.  
  53. String f = null;
  54. String[]registeredAccount = new String[2];
  55. int ctr = 0;
  56.  
  57. while ((f = br.readLine()) != null){
  58. registeredAccount[ctr] = f;
  59. ctr++;
  60. }
  61. if(username1.equalsIgnoreCase(registeredAccount[0])&&pass1.equalsIgnoreCase(registeredAccount[1])){
  62.  
  63. System.out.println("Successfully Logged In");
  64.  
  65. }
  66. else{
  67. System.out.println("Incorrect Username or Password");
  68. }
  69.  
  70. }
  71.  
  72.  
  73. }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement