I'm trying to learn Java and as part of a task I'm working on, a user will sign up with a username and password which then get hashed using Java's hashCode()
and added to a text file in the form of username,password.
Now when a user logs in, I am attempting to hash their input and compare it to the .txt
file to ensure the correct credentials have been entered.
I originally did this by searching the .txt
file line by line until the entered username appeared using the contains
method by which I then split the line at the comma giving me the password for the entered username to check.
How could I do this same thing but now with a hashed int value? Please see my code for reference
Any help would be greatly appreciated!
Currently, I have tried converting the hashed value back to String then using contains which it will not allow.
int UsernameHash = Username.hashCode();
int PasswordHash = Password.hashCode();
@SuppressWarnings("resource")
Scanner FileContent = new Scanner(new File("Users.txt"));
while (FileContent.hasNextLine()) {
String Line = "";
Line = FileContent.nextLine();
if(Line.contains(UsernameHash)) {
String FullLine = Line;
String[] loginAuth = FullLine.split(",");
String Pass = loginAuth[1];
if(Pass.equals(PasswordHash)) {
System.out.println("\n Thank You for logging in, please proceed!");