如何测试 android java 中的密码字符串?

How do I test a password string in android java?

我正在做一个项目,目前正在测试简单的登录,还没有考虑安全措施,我遇到了一个问题,我无法像用户名一样将密码输入与简单字符串进行比较。

我到处查看,但几乎只显示安全措施,我只是想知道如何以更简单的方式使用类似于字符串比较的方法来做到这一点。

编辑 - 它仍然是一个不稳定的程序,我只是在测试方法,我做的功能是这个(葡萄牙语 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();


    }
}

我确定问题出在密码 TextField 分配中的 findViewById(R.id.name);您可能应该将其更改为引用密码 TextField(必须类似于 TextField password = findViewById(R.id.password)

TextView password = findViewById(R.id.name);

你说你的密码视图也是名称,这种类型的逻辑错误非常容易通过简单的调试发现;)