Friday 14 June 2019

Checking username and password in Android using SQLite database





I want to get query from SQLite Database in my APP that consist of name, surname, username and also password.



when I click login button, it made crash. here is my code ##



public String Login(String Username, String Password) {


String Q = "SELECT * FROM " + DBHelper.TBLname + " WHERE "
+ DBHelper.ColumnUser + " = " + Username
+ " AND " + DBHelper.ColumnPass + " = " + Password;

Cursor LoginQuery = MyDB.rawQuery(Q, null);

if (LoginQuery == null) {
LoginQuery.close();
String LoginResult = "Wrong User Name and Password";
return LoginResult;

}
LoginQuery.moveToFirst();
String LoginResult = LoginQuery.getString(3);
LoginQuery.close();
return LoginResult;
}

Answer



Try this without dbhelper:




SELECT * FROM YOUR TABLE WHERE Username=Your Username AND Password=Your Password

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...