Cannot understand why following code doesn't work properly. Firstly, system getting input from the user. Then system reads all data from .txt file and compare with the user input. But the system never finds similar username and password.
The idea is to create simple login that based on the stored username and password in .txt file. Could someone help?
private static void login() { String record = null; FileReader in = null; try { in = new FileReader("adminlogin.txt"); BufferedReader br = new BufferedReader(in); Scanner keyboard = new Scanner(System.in); System.out.print("Username: "); String user = keyboard.nextLine(); System.out.print("Password: "); String pass = keyboard.nextLine(); while ((record = br.readLine()) !=null) { if (user.equals(record) && pass.equals(record)) { Mainemenu menu = new Mainemenu(); menu.AdminMenu(); } else { System.out.println("________----Error----________\n press 'Enter' to continue..."); keyboard.nextLine(); checkInput(); } } } catch (IOException e) { e.getCause(); } }
boolean existsLineEqualTo(BufferedReader reader, String userName).