我正在尝试创建更改密码功能...但我不知道为什么会收到错误,尽管我输入了正确的密码。它总是返回失败。
我遵循此代码 Manager Users Firebase
这是我的代码
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();
}
}
});
答案 0 :(得分:1)
获取密码的代码不正确:
String pass = edtOldPass.getEditText().toString();
在TextInputLayout
上调用getEditText()会返回包含EditText
窗口小部件,而不是EditText
的字符串值。
将其更改为:
String pass = edtOldPass.getEditText().getText().toString();