【发布时间】:2019-06-29 04:36:08
【问题描述】:
我正在做一个项目,目前正在测试简单的登录,但尚未考虑安全措施,我遇到了一个问题,我无法将密码输入与用户名相同的简单字符串进行比较。
我到处查看,但几乎只显示了安全措施,我只是想知道如何以更简单的方式执行此操作,类似于字符串比较。
edit - 它仍然是一个不稳定的程序,我只是在测试方法,我制作的功能是这个(葡萄牙语 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();
}
}
【问题讨论】:
-
具体有什么区别?一些代码来说明问题也会有所帮助
-
我希望密码在数据库中经过哈希处理,对提供的密码执行相同操作,然后比较(字符串比较)2 个哈希密码
-
对不起,我更新了问题
-
显示的是哪个吐司?
-
@Garikai 由于密码部分,目前只有第二个(失败)
标签: java android android-studio passwords