I'm trying to perform user verification and login while accessing the system. I am using the following codes:
public int login(String username,String password)
{
String[] selectionArgs = new String[]{username, password};
try
{
int i = 0;
Cursor c = null;
c = db.rawQuery("select * from usuarios where login=? and senha=?", selectionArgs);
c.moveToFirst();
i = c.getCount();
c.close();
System.out.println("AQUIII " + i);
return i;
}
catch(Exception e)
{
e.printStackTrace();
}
return 0;
}
And calling this function:
if (bd.login(usuario.toString(),senha.toString()) == 0 ){
usuario.setError("");
senha.setError("");
Toast toast = Toast.makeText(MainActivity.this, "Senha ou usuário não existente", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP | Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
}
But he is not doing the action as expected. Any data that I enter as user and password it gives that does not exist.