User already created but I can't login. It keep saying wrong email and password. I can't find what's wrong since I am not really good.
But I've tried to change and re-type the select Query but nothing changed.
DatabaseHelper.java
public boolean checkUser(String email) {
String checkQuery = "SELECT * FROM " + USER_TABLE + " WHERE " + COLUMN_EMAIL + " = " + "'" + email + "'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(checkQuery, null);
cursor.moveToFirst();
if (cursor.getCount() > 0) {
return false;
}
return true;
}
public boolean getUser (String email, String password) {
String selectQuery = "SELECT * FROM " + USER_TABLE + " WHERE " + COLUMN_EMAIL + " = " + "'" + email + "'" +
" AND " + COLUMN_PASS + " = " + "'" + password + "'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
cursor.moveToFirst();
if(cursor.getCount()>0) {
return true;
}
cursor.close();
db.close();
return false;
}
LoginActivity.java
if(session.loggedin()){
startActivity(new Intent(LoginActivity.this,HomeActivity.class));
finish();
}
@Override
public void onClick(View v){
switch (v.getId()){
case R.id.login:
login();
break;
case R.id.signup:
startActivity(new Intent(LoginActivity.this,RegisterActivity.class));
break;
default:
}
}
private void login(){
String emails = email.getText().toString();
String passwords = password.getText().toString();
if(db.getUser(emails,passwords)){
startActivity(new Intent(LoginActivity.this, HomeActivity.class));
finish();
}else {
Toast.makeText(getApplicationContext(),"Wrong email or password!", Toast.LENGTH_SHORT).show();
}
}