我正在做一个项目,目前正在测试简单的登录,还没有关于安全措施,我遇到了一个问题,我无法将密码输入与简单的字符串进行比较与用户名相同。
我到处看,但只有安全措施几乎出现,我只是想知道我如何以更简单的方式做到这一点,类似于字符串比较。
编辑 - 它仍然是一个不稳定的程序,我只是在测试方法,我所做的功能是这样的(葡萄牙语顺便说一句(:
public void login_try(View view) {
//Obter o nome de utilizador e transformar em string
TextView name = findViewById(R.id.name);
String nome = name.getText().toString();
//Obter a password e transformar em string
TextView password = findViewById(R.id.name);
String palavra_passe = password.getText().toString();
//Testa o nome e a password para dar login
if (nome.equals("Rubas") && palavra_passe.equals("123")) {
Context context = getApplicationContext();
CharSequence text = "Entrou com sucesso!!!!";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
} else {
Context context = getApplicationContext();
CharSequence text = "Login falhado :(";
int duration = Toast.LENGTH_SHORT;
Toast toast = Toast.makeText(context, text, duration);
toast.show();
}
}
我确定问题源于密码TextField
分配findViewById(R.id.name)
;您可能应该将其更改为引用密码TextField
(必须类似于TextField password = findViewById(R.id.password)
(
TextView password = findViewById(R.id.name);
您告诉密码视图也是名称,这种类型的逻辑错误很容易通过简单的调试;)