Screen login SQLITE

Asked

Viewed 547 times

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?

  • @acklay no. The return of the login method is always 0

  • But already checked if in fact the user is registered!?

  • @acklay when I give a print on the list that has registered users the same is there.

1 answer

1


As you are using an editText you will have to make this change:

of:

if (bd.login(usuario.toString(),senha.toString()) == 0 ){

for

if (bd.login(usuario.getText().toString(),senha.getText().toString()) == 0){

Browser other questions tagged

You are not signed in. Login or sign up in order to post.