Jonas
Jonas

Reputation: 128797

How to check the password from an EditView?

I use an EditText with android:password="true" to let the user type the password. Then I want to compare the password with a hard coded password when the user presses a button.

But I can't compare the password with a String "mypassword". Here is the code I use to check the password:

EditText pw = (EditText) findViewById(R.id.pwdTxt);
if(pw.getText().equals("mypassword")) {
    Intent i = new Intent(LoginActivity.this, LinkpageActivity.class);
    startActivity(i);
} else {
    // Wrong password
}

The comparison pw.getText().equals("mypassword") returns false even if I type the correct password. How should I check the password from an EditText?

Upvotes: 4

Views: 356

Answers (1)

Andreas Wong
Andreas Wong

Reputation: 60506

Maybe you could try

pw.getText().toString().equals("mypassword")

Upvotes: 4

Related Questions