我有一个包含名称和密码的数据库。当有人输入两个参数时,我需要在数据库上选择正确的行。我知道如果我只想选择我可以做的名字:
如何选择名称和密码?谢谢!
public void Register(View view){
String User = usr.getText().toString();
String Password = pass.getText().toString();
if(User.isEmpty() && Password.isEmpty()) Toast.makeText(this, "You Must fill all the fields", Toast.LENGTH_LONG).show();
else{
if(User.equals("admin") && Password.equals("admin")) ActivarActivityMenuAdministrador();
else{
AdminSQLiteOpenHelper adminsql = new AdminSQLiteOpenHelper(this, "DBUsers",null,1 );
SQLiteDatabase DB = adminsql.getWritableDatabase();
Cursor fila = DB.rawQuery("select name, password from DBUsers where nombre=" + User, null);
}
}
}
答案 0 :(得分:1)
如果您将密码存储为纯文本:
DB.rawQuery("select name, password from DBUsers where name=" + User + " AND password=" + Password, null);
旁注: 永远不要将参数直接传递给SQL查询,请选中this,而应执行以下操作:
DB.rawQuery("SELECT name, password FROM DBUsers WHERE name = ? AND password = ?", new String[] {User, Password});