我正在研究一个项目,目前正在测试简单的登录名,还没有考虑安全措施,所以遇到了一个问题,我无法像使用用户名一样将密码输入与简单字符串进行比较。
我四处张望,但只有安全措施浮出水面,我只是想知道如何以更简单的方式(类似于字符串比较)来做到这一点。
编辑-这仍然是一个易失程序,我只是在测试方法,而我做的功能是这个(葡萄牙语btw):
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();
}
}
答案 0 :(得分:0)
我确定问题出在密码findViewById(R.id.name)
分配上的TextField
上;您可能应该更改密码以引用密码TextField
(必须类似TextField password = findViewById(R.id.password)
)
答案 1 :(得分:-1)
TextView password = findViewById(R.id.name);
您告诉您的密码视图也是名称,通过简单的调试就很容易发现这种逻辑错误;)