I got this code below to do a simple password (hashed) check function. But I encountered a problem, the code seem to work only for single line data in the file, the check works for Line1 but not Line2, I am unsure what is wrong. The data is shown below
the result is supposed to be hashedP matching either Line1 or 2. But it end up matching Line1 only
260670134225f2a24b59121739fec73584b0ddb6b49c39e31bd1df5483ac144d //Line1
cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90 //Line2
Code:
public static void LoginMenu() {
System.out.println("Please Enter Your Password: ");
Scanner UserPass = new Scanner(System.in);
String UserP = UserPass.nextLine();
String hashedP = Utility.getHash(UserP);
File file = new File("admin.dat");
try {
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
String fileline = scanner.nextLine();
if (!(fileline.equals(hashedP))) {
System.out.println("Login Failed!");
LoginMenu();
}
else {
System.out.println("Login Successful.\n");
AdminMenu();
}
}
scanner.close();
}
catch (FileNotFoundException exc) {
exc.printStackTrace();
}
}