Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package taskperf6;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.util.Scanner;
- public class TaskPerf6 {
- public static void main(String[] args)throws FileNotFoundException, IOException{
- Scanner input = new Scanner(System.in);
- System.out.println("1.Registration");
- System.out.println("2.Log in");
- System.out.print("Select Option: ");
- int select = input.nextInt();
- switch(select){
- case 1:
- String username;
- String pass;
- String strl = input.nextLine();
- BufferedWriter writer = new BufferedWriter(new FileWriter("C:/records.txt"));
- System.out.print("Enter Username: ");
- username = input.nextLine();
- writer.write(username);
- writer.newLine();
- System.out.print("Enter Password: ");
- pass = input.nextLine();
- writer.write(pass);
- writer.close();
- System.out.println("Successfully Registered");
- System.out.print("Do You Want to Log in Now[Y/N]:");
- String YesNo = input.nextLine();
- if(YesNo.equalsIgnoreCase("Y")){
- File file = new File("C:/records.txt");
- FileReader fr = new FileReader(file);
- BufferedReader br = new BufferedReader(fr);
- String username1;
- String pass1;
- String strl1 = input.nextLine();
- System.out.print("Enter Your Username: ");
- username1 = input.nextLine();
- System.out.print("Enter Your Password: ");
- pass1 = input.nextLine();
- String s = null;
- String[] registeredAccount = new String[2];
- int ctr = 0;
- while((s = br.readLine()) != null){
- registeredAccount[ctr] = s;
- ctr++;
- }
- if(username1.equalsIgnoreCase(registeredAccount[0]) && pass1.equalsIgnoreCase(registeredAccount[1])){
- System.out.print("Successfully Logged in");
- }
- else{
- System.out.print("Incorrect Username or Password");
- }
- }
- else if(YesNo.equalsIgnoreCase("N")){
- System.out.print("End of Program");
- }
- break;
- case 2:
- File file = new File("C:/records.txt");
- FileReader fr = new FileReader(file);
- BufferedReader br = new BufferedReader(fr);
- String username1;
- String pass1;
- String strl1 = input.nextLine();
- System.out.print("Enter Your Username: ");
- username1 = input.nextLine();
- System.out.print("Enter Your Password: ");
- pass1 = input.nextLine();
- String s = null;
- String[] registeredAccount = new String[2];
- int ctr = 0;
- while((s = br.readLine()) != null){
- registeredAccount[ctr] = s;
- ctr++;
- }
- if(username1.equalsIgnoreCase(registeredAccount[0]) && pass1.equalsIgnoreCase(registeredAccount[1])){
- System.out.print("Successfully Logged in");
- }
- else{
- System.out.print("Incorrect Username or Password");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement