Advertisement
Guest User

EricsonMalunesLogin&Reg

a guest
Feb 11th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.36 KB | None | 0 0
  1. package taskper16;
  2. import java.io.*;
  3. import java.util.Scanner;
  4. /**
  5.  *
  6.  * @author Complab212-PC50
  7.  */
  8. public class TaskPer16 {
  9.  
  10.     /**
  11.      * @param args the command line arguments
  12.      */
  13.     public static void main(String[] args) {
  14.         // TODO code application logic here
  15.         Scanner sc = new Scanner(System.in);
  16.        int choice;
  17.        
  18.        System.out.println("Choose the following function : ");
  19.        System.out.println("1.Register");
  20.        System.out.println("2.Login");
  21.        System.out.println("3.Exit");
  22.        choice = sc.nextInt();
  23.        switch (choice){
  24.            case 1:
  25.               try{
  26.                   Scanner scan = new Scanner(System.in);
  27.                File file = new File("record.txt");
  28.                FileWriter fw = new FileWriter(file);
  29.                PrintWriter pw = new PrintWriter(fw);
  30.                
  31.                System.out.println("Enter Username : ");
  32.                String user = scan.nextLine();
  33.                System.out.println("Enter Password : ");
  34.                String pass = scan.nextLine();
  35.                
  36.                pw.println(user);
  37.                pw.println(pass);
  38.                pw.close();
  39.                
  40.                
  41.                System.out.println(" ");
  42.                System.out.println("==============LOGIN==============");
  43.                System.out.println("Enter username : ");
  44.                String luser = scan.nextLine();
  45.                System.out.println("Enter password : ");
  46.                String lpass = scan.nextLine();
  47.                
  48.                FileReader fr = new FileReader("record.txt");
  49.                BufferedReader br = new BufferedReader(fr);
  50.                
  51.                String one = br.readLine();
  52.                String two = br.readLine();
  53.                
  54.                if (luser.equals(one)&& lpass.equals(two)){
  55.                    System.out.println("Login Succesfull");
  56.                }
  57.                else {
  58.                    System.out.println("Login Failed");
  59.                }
  60.               }
  61.                catch(IOException e){
  62.                    System.out.println("ERROR");
  63.                }
  64.                
  65.                break;
  66.            case 2:
  67.                try{
  68.                Scanner scan = new Scanner(System.in);
  69.                System.out.println(" ");
  70.                System.out.println("==============LOGIN==============");
  71.                System.out.println("Enter username : ");
  72.                String luser = scan.nextLine();
  73.                System.out.println("Enter password : ");
  74.                String lpass = scan.nextLine();
  75.                
  76.                FileReader fr = new FileReader("record.txt");
  77.                BufferedReader br = new BufferedReader(fr);
  78.                
  79.                String one = br.readLine();
  80.                String two = br.readLine();
  81.                
  82.                if (luser.equals(one)&& lpass.equals(two)){
  83.                    System.out.println("Login Succesfull");
  84.                }
  85.                else {
  86.                    System.out.println("Login Failed");
  87.                }
  88.               }
  89.                catch(IOException e){
  90.                    System.out.println("ERROR");
  91.                }
  92.                
  93.                
  94.                
  95.                break;
  96.              
  97.            case 3 :
  98.                System.exit(0);
  99.                
  100.        
  101.     }
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement