I am creating an application and I want the application to automatically register in a text file if the user is already logged in. In the text file, I have "alex | ppp", which corresponds to an entry in the database. The next method is called the first
private void rememberedLogIn(){
String filename = "UserInfo.txt";
String info = "";
String user = "";
String pass = "";
try{
FileInputStream fIn = openFileInput(filename);
BufferedReader r = new BufferedReader(new InputStreamReader(fIn));
info = r.readLine();
}catch(IOException e){
e.printStackTrace(System.err);
}
for(int i =0; i < info.length();i++){
if(info.charAt(i) == '|' ){
user = info.substring(0,i);
pass = info.substring(i+1);
GlobalVar.loggedIn= true;
break;
}
}
new InitialStuff().execute(user,pass);
}
I double checked the values for the user and went through and they are expected to be "alex" and "ppp". The following InitialStuff is called, this is the corresponding code:
public class InitialStuff extends AsyncTask<String, Void, Toon>{
int prog = 0;
@Override
protected Toon doInBackground(String... params) {
android.os.Debug.waitForDebugger();
Toon toon = null;
Database db = new Database();
db.establishConnection();
if(db.tryLogIn(params[0], params[1])){
prog = 2;
publishProgress();
toon = db.getToonFromDB(params[0]);
prog = 4;
}else prog = 3;
publishProgress();
return toon;
}}
The problem occurs when I call db.tryLogin (), which looks like
public boolean tryLogIn(String toonName, String toonPass){
try{
while(!connected) establishConnection();
String sqlQuery = "SELECT Password FROM Toons WHERE Name LIKE '" + toonName+"';";
Statement stmt = con.createStatement();
ResultSet rSet = stmt.executeQuery(sqlQuery);
if(rSet.next()){
String dbPass = rSet.getString(1).trim();
if(dbPass.equals(toonPass))
return true;
}
}
catch(Exception e){ }
return false;
}
I checked that dbPass returns from the database as "ppp", which matches toonPass, but it skips true and returns false instead.
If this helps, this informational eclipse gives me about two
toonPass "ppp" (id = 830041185816) count 3
hashCode 0
offset 5
(id = 830041185744)
[0] a
[1] l
[2] e
[3] x
[4] | [5] p
[6] p
[7] p
dbPass "ppp" (id = 830041708816) count 3
hashCode 0
0
(id = 830041709136)
[0] p
[1] p
[2] p
, "ppp" tryLogin(), , - , .
EDIT: ... sorta. .equals() for, .