SQLITE login screen

0

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.

    
asked by anonymous 23.06.2017 / 19:03

1 answer

1

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

From:

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

for

if (bd.login(usuario.getText().toString(),senha.getText().toString()) == 0){
    
10.07.2017 / 04:36