mardi 25 août 2015

Error in either if statement or in query

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() {
        String rpq = regPwdQuery().toString();

        @Override
       public void onClick(View v) {
            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.toString();
    String regQuery = "SELECT COUNT(*) AS COUNT FROM UsrPass_table WHERE Pwrd ='" + regPwdData + "'";
    SQLiteDatabase uDB = usrDB.getWritableDatabase();
    Cursor cursor = uDB.rawQuery(regQuery, null);
    while (cursor.moveToNext()){
       count = cursor.getCount();
    }
    cursor.close();
    return count;
}

Aucun commentaire:

Enregistrer un commentaire