Reputation: 111
I'm trying to create Change Password feature... but I don't know why getting the error, although I type the correct password. It's always returning failed.
I follow this code from Manager Users Firebase
and this is my code
edtOldPass = (TextInputLayout) findViewById(R.id.edt_oldpass);
mCurrentUser = FirebaseAuth.getInstance().getCurrentUser();
String email = mCurrentUser.getEmail();
String pass = edtOldPass.getEditText().toString();
AuthCredential credential = EmailAuthProvider.getCredential(email, pass);
mCurrentUser.reauthenticate(credential).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Intent newpassIntent = new Intent(ReAuthActivity.this, ChangePassActivity.class);
startActivity(newpassIntent);
} else {
Toast.makeText(ReAuthActivity.this, "Incorrect Password", Toast.LENGTH_SHORT).show();
}
}
});
Upvotes: 1
Views: 317
Reputation: 38289
This code to get the password is not correct:
String pass = edtOldPass.getEditText().toString();
Calling getEditText() on a TextInputLayout
returns the contained EditText
widget, not the string value of the EditText
.
Change it to this:
String pass = edtOldPass.getEditText().getText().toString();
Upvotes: 1