Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package taskper16;
- import java.io.*;
- import java.util.Scanner;
- /**
- *
- * @author Complab212-PC50
- */
- public class TaskPer16 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- Scanner sc = new Scanner(System.in);
- int choice;
- System.out.println("Choose the following function : ");
- System.out.println("1.Register");
- System.out.println("2.Login");
- System.out.println("3.Exit");
- choice = sc.nextInt();
- switch (choice){
- case 1:
- try{
- Scanner scan = new Scanner(System.in);
- File file = new File("record.txt");
- FileWriter fw = new FileWriter(file);
- PrintWriter pw = new PrintWriter(fw);
- System.out.println("Enter Username : ");
- String user = scan.nextLine();
- System.out.println("Enter Password : ");
- String pass = scan.nextLine();
- pw.println(user);
- pw.println(pass);
- pw.close();
- Scanner enter = new Scanner(System.in);
- System.out.println(" ");
- System.out.println("==============LOGIN==============");
- System.out.println("Enter username : ");
- String luser = enter.nextLine();
- System.out.println("Enter password : ");
- String lpass = enter.nextLine();
- FileReader fr = new FileReader("record.txt");
- BufferedReader br = new BufferedReader(fr);
- String one = br.readLine();
- String two = br.readLine();
- if (luser.equals(one)&& lpass.equals(two)){
- System.out.println("Login Succesfull");
- }
- else {
- System.out.println("Login Failed");
- }
- }
- catch(IOException e){
- System.out.println("ERROR");
- }
- break;
- case 2:
- try{
- Scanner enter = new Scanner(System.in);
- System.out.println("LOGIN");
- System.out.println("Enter username : ");
- String luser = enter.nextLine();
- System.out.println("Enter password : ");
- String lpass = enter.nextLine();
- FileReader fr = new FileReader("record.txt");
- BufferedReader br = new BufferedReader(fr);
- String one = br.readLine();
- String two = br.readLine();
- if (luser == one && lpass == two){
- System.out.println("Login Succesfull");
- }
- else {
- System.out.println("Login Failed");
- }
- }
- catch(IOException a){
- System.out.println("ERROR");
- }
- break;
- case 3 :
- System.exit(0);
- }
- }
- }
Add Comment
Please, Sign In to add comment