0
I’m needing the parameters used in the button to query the database (the code was the result of another post response) when trying to implement the function inside the baton I could not get it to work.
// FUNÇÃO TESTE LOGIN 1
public void UsuarioAutenticar (int id, String user, String senha) {
LoginModelo usuario = new LoginModelo();
String selectQuery = "SELECT * FROM TBL_USRS WHERE KEY_USER = '" + user + "' and KEY_SENHA = '" + senha + "'";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor != null) {
//final Usuario usuario = new Usuario ();
cursor.moveToFirst();
usuario.setId(Integer.parseInt(cursor.getString(0)));
usuario.setNome(cursor.getString(1).toString());
usuario.setSenha(cursor.getString(6).toString());
}
}// FIM FUNÇÃO TESTE LOGIN 1
// função teste login 2
public LoginModelo UsuarioAutenticado (String user, String senha){
final SQLiteDatabase db = this.getReadableDatabase();
/**
Aqui você deve colocar todas as colunas que deseja recuperar
*/
final String[] properties = {"id", "nome", "senha"};
final Cursor cursor = db.query("TBL_USRS", properties, "KEY_USER = ? and KEY_SENHA = ?", new String[]{user, senha}, null, null, null, null);
/**
* Este método retornará false se o cursor estiver vazio.
*/
if(cursor.moveToFirst()){
final LoginModelo usuario = new LoginModelo ();
usuario.setId(Integer.parseInt(cursor.getString(0)));
usuario.setNome(cursor.getString(1).toString());
usuario.setSenha(cursor.getString(6).toString());
return usuario;
}else{
return null;
}
} // FIM FUNÇÃO TESTE LOGIN 2
tried so
checkLOGON.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Resgatando valores dos edittext
EditText checkNome = findViewById(R.id.user);
EditText checkSenha = findViewById(R.id.login);
//convertendo em strings
String checkNomes = checkNome.getText().toString();
String checkSenhas = checkSenha.getText().toString();
// comparando os campos digitados com os da variavel predefinida
//checarLogin
String usuario;
usuario = databaseHelper.UsuarioAutenticado( int id, user, senha);
if (usuario != null) {
Intent intent = new Intent(MasterLogin.this, MainActivity.class);
startActivity(intent);
} else
Toast.makeText(MasterLogin.this, "Usuario não encontrado", Toast.LENGTH_SHORT).show();
}
and so:
LoginModelo = databaseHelper.UsuarioAutenticado(int id, user , senha);
if(LoginModelo!=null) {
Intent intent = new Intent(MasterLogin.this, MainActivity.class);
startActivity(intent);
}else
Toast.makeText(MasterLogin.this, "Usuario não encontrado", Toast.LENGTH_SHORT).show();
}
but I understand it’s not right I tested this line as suggested:
usuario = databaseHelper.UsuarioAutenticar( int id, checkNome.getText().toString(),checkSenha.getText().toString());
and
usuario = databaseHelper.UsuarioAutenticar( checkNomes,checkSenhas);
Obs: I tested with the two functions select Authenticate User and Authenticated User.
I couldn’t reach a conclusion about my mistakes in this verification step for login.
Which error appears?
– Murillo Comino
'.class' expected
– user3873165
'.class' expected ';' expected
– user3873165
when I use the second code it returns: ...""(java.lang.String, java.lang.String)' on a null Object Reference
– user3873165
it seems that I was making a brief confusion between builder and class. now appear other errors. E/Spannablestringbuilder: SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
– user3873165
I watched the error logs and went through one by one until I completed the flaws in my failed code.
– user3873165