All I want to know is weather my problem resides in my "if" statement or in my query... If you want to be generous and help me further than that it would be appreciated but as a beginner I feel its good for me to trouble shoot for myself.
My problem is that no matter what value I put into the editText box the result is returning true(taking me to the next screen of my app). Unless I leave it blank which it is then doing what it is supposed to which is showing a text saying "You did not enter a password" Can someone please tell me where my problem lies?
public void buttonWork() {
button_credCheck.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Integer rpq = regPwdQuery();
String isEnteredStr = editText_pwdInput.getText().toString();
if (TextUtils.isEmpty(isEnteredStr)) {
Toast.makeText(LogInActivity.this, "You did not enter a password!", Toast.LENGTH_LONG).show();
}
else if
(rpq.equals(1)) {
Intent myIntent = new Intent(LogInActivity.this, FindInfoActivity.class);
startActivity(myIntent);
}
else {
Toast.makeText(LogInActivity.this, "Incorrect Password", Toast.LENGTH_LONG).show();
}
}
});
}
public Integer regPwdQuery() {
int count = 0;
String regPwdData = editText_pwdInput.getText.toString();
String regQuery = "SELECT COUNT(*) AS COUNT FROM UsrPass_table WHERE Pwrd ='" + regPwdData + "'";
SQLiteDatabase uDB = usrDB.getReadableDatabase();
Cursor cursor = uDB.rawQuery(regQuery, null);
while (cursor.moveToNext()){
count = cursor.getCount();
}
cursor.close();
return count;
}
EDIT: I have tried changing my else if to: rpq.equals(2) since I was told that getCount will always return 1. This caused the all passwords (even correct ones, verified to exist in DB) to be blocked saying incorrect password.. so if I leave my if statement to check for a 1 then it doesn't block incorrect passwords and if I set my if statement to check for 2 then it blocks everything.. my assumption is that the error is in my query somewhere... maybe I need a way to add 1 to "cnt" if the query returns true... I tried adding a cnt++ in a few different places of my regPwdQuery but no luck.. can anyone help me?