Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package login;
- import java.io.*;
- import java.util.Scanner;
- public class LogIn {
- public static void main(String[] args){
- Scanner s = new Scanner(System.in);
- System.out.println("Please choose on the following: \n1. Register \n2. Log-in");
- int choice = s.nextInt();
- switch (choice) {
- case 1:
- try {
- Scanner scan = new Scanner(System.in);
- File file = new File("out1.txt");
- FileWriter fw = new FileWriter(file);
- PrintWriter pw = new PrintWriter(fw);
- //signup
- System.out.println("\nEnter your desired Username:");
- String user = scan.nextLine();
- System.out.println("Enter your desired Password:");
- String pass = scan.nextLine();
- pw.println(user);
- pw.println(pass);
- pw.close();
- //login
- System.out.println("\nPlease Log-in \nEnter Username:");
- String luser = scan.nextLine();
- System.out.println("Enter Password:");
- String lpass = scan.nextLine();
- //filereader
- FileReader fr = new FileReader("out1.txt");
- BufferedReader br = new BufferedReader(fr);
- String line1 = br.readLine();
- String line2 = br.readLine();
- //login if-else
- if(luser.equals(line1) && lpass.equals(line2)){
- System.out.println("\nSuccessfully logged in");
- }
- else{
- System.out.println("\nIncorrect username or password");
- }
- } catch (IOException ex) {
- System.out.println("\nError!");
- } break;
- case 2:
- try {
- Scanner scan = new Scanner(System.in);
- //login
- System.out.println("\nPlease Log-in \nEnter Username:");
- String luser = scan.nextLine();
- System.out.println("Enter Password:");
- String lpass = scan.nextLine();
- //filereader
- FileReader fr = new FileReader("out1.txt");
- BufferedReader br = new BufferedReader(fr);
- String line1 = br.readLine();
- String line2 = br.readLine();
- //login if-else
- if(luser.equals(line1) && lpass.equals(line2)){
- System.out.println("\nSuccessfully logged in");
- }
- else{
- System.out.println("\nIncorrect username or password");
- }
- } catch (IOException ex) {
- System.out.println("\nError!");
- } break;
- default:
- System.out.println("\nInvalid input");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement