0

我四处搜寻,但似乎找不到可以解决我的问题的答案。我试图检查用户是否登录,如果用户名和密码在数据库中匹配,它应该检查数据库并导航到下一页。我不知道我哪里出错了,因为使用下面的代码,即使用户名和密码不匹配(用户名错误而密码正确)我也能够登录,但如果密码错误(用户名正确或错误无关紧要),我设置的错误信息出现了。是因为密码是唯一被读取的并且用户名已经被覆盖了吗?我是android和java的新手,所以请帮忙。非常感谢!

$   public void run()
                {
                    button.setOnClickListener(new OnClickListener() {
                        public void onClick(View v) {       

                            Query query = new Query();
                            query.select("x.username, x.password");
                            query.from("AccountLogin", "x");
                            AttributeTest ts = new AttributeTest();
                            ts.setOperator(AttributeTest.EQUAL);
                            ts.setAttribute("username");
                            ts.setValue(un.getText());
                            ts.setAttribute("password");
                            ts.setValue(pw.getText());
                            query.setTestCriteria(ts);



                            QueryResultSet qs = FinalDB.executeQuery(query);
                            if (!qs.isEmpty()) {

                                Intent goToNextActivity = new Intent(FinalActivity.this,    HomePage.class);
                                startActivity(goToNextActivity);
                            } else {
                                error.setText("Login failed. Username and/or password doesn't match.");
                            }
                        }
                    });
                }
            });

        }


    }).start();
}

}

4

1 回答 1

0

Try this. check where condition or where query like this.

This code is only check password.

 Query query = new Query();
            query.select("x.username, x.password");
                                query.from("AccountLogin", "x");
            AttributeTest ts2 = new AttributeTest();
            ts2.setAttribute("x.password");

            ObjectList v = new ObjectList();
            v.add("password"); // use orignal password

            ts2.setValue(v);
            ts2.setOperator(AttributeTest.IN);
            query.where(ts2);

            query.setTake(take);
            query.setSkip(skip);

            lowIndex = skip;
            highIndex = lowIndex;

            if (!qs.isEmpty()) {

           Intent goToNextActivity = new Intent(FinalActivity.this,    HomePage.class);
           startActivity(goToNextActivity);
           } else {
           error.setText("Login failed. Username and/or password doesn't match.");
            }
于 2012-09-26T12:22:28.790 回答