0
I am trying to perform the verification of user existence and login when performing the access in the system. I’m 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 the call of that 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 performing the action as expected. Any data I inform as user and password he gives that does not exist.
Showing some error in your logcat?
– viana
@acklay no. The return of the login method is always 0
– Lucas Charles
But already checked if in fact the user is registered!?
– viana
@acklay when I give a print on the list that has registered users the same is there.
– Lucas Charles