mercredi 31 décembre 2014

android database: how to match credentials from sqlite database

I've a user info table with 8 columns stored in sqlite database. I'm having problem in comparing the user entered credentials with the one that stored in database. My app says that user name and password does not match, although i'm entering the correct values.


method in main activity



@Override
public void onClick(View v) {
// TODO Auto-generated method stub
ffCode = ed_login.getText().toString();
password = ed_password.getText().toString();
// check if any of edit text is empty
if(ffCode.equals(""))
{
Toast.makeText(getApplicationContext(), "Please enter your FF code", Toast.LENGTH_LONG).show();
return;
}
else if (password.equals(""))
{
Toast.makeText(getApplicationContext(), "Please enter your password", Toast.LENGTH_LONG).show();
return;
}
Log.e("calling database", "yes");
Db_getUserDetail myDb= new Db_getUserDetail(MainActivity.this);

//this is the method to query
String storedffcode = myDb.getCodeAndPassword(ffCode,password);
String storedpassword = myDb.getCodeAndPassword(ffCode,password);
myDb.close();

if(ffCode.equals (storedffcode) && password.equals (storedpassword))
{
Toast.makeText(getApplicationContext(), "Congrats: Login Successfull", Toast.LENGTH_LONG).show();

}
else
{
Toast.makeText(getApplicationContext(), "User Name or Password does not match", Toast.LENGTH_LONG).show();
}
}
});


method of database helper class



public String getCodeAndPassword(String ffCode,String password)
{
Log.e("retrieving ff code", "yes");
SQLiteDatabase db = getWritableDatabase();
// Cursor cursor = db.query("user_detail", null, " ff_code=?",new String[]{ffCode,password}, null, null, null);
Cursor cursor = db.rawQuery("SELECT ff_code, user_pwd FROM " + "user_detail" + " WHERE ff_code = '"+ ffCode + "' AND user_pwd ='"+ password+ "'", null);
if(cursor.getCount()<1)
{
cursor.close();
return "Not Exist";
}
Log.e("found ff code", "yes");
cursor.moveToFirst();
String ffcode= cursor.getString(cursor.getColumnIndex("ff_code"));
return ffcode;
}

Aucun commentaire:

Enregistrer un commentaire