I'm on with this problem for a week now..and i can't find what's really wrong with this. I'm comparing 2 strings. First is from a user input then the second is from the random access file read. the first string is a password converted to string and the 2nd is a password converted to string written to a random access file. here's my code snippet.
public boolean isRegistered(String pass, int id){
boolean here = false;
int i = 0;
pass = padding(pass);
String s;
try{
access = new RandomAccessFile(file, "r");
do{
access.seek(i*RECORD);
access.getFilePointer();
if(id == access.readInt()){
access.seek(i*RECORD+ID_SIZE);
access.getFilePointer();
s = String.valueOf(access.readUTF());
System.out.println("read s = "+s);
System.out.println("password is ="+pass);
System.out.println("read s.length = "+s.length());
System.out.println("pass.length = "+pass.length());
if(pass.equals(s){
here = true;
break;
}else{
System.out.println("Wrong password");
here = false;
break;
}
}
i++;
}while(access.getFilePointer()!= access.length());
access.close();
}catch(Exception e){
JOptionPane.showMessageDialog(null,"isRegistered "+e.getMessage());
}
return here;
}
my file contains exactly the same password and thus it should return true. but unfortunately
updated
already.. i really need your help. Thanks for taking time reading this :)
//i have known the problem :) Strings should have the same size and .equals should be imposed. thanks though :)
This code is working now