重新验证失败的Firebase Android

时间:2017-07-02 16:07:56

标签: android firebase firebase-authentication

我正在尝试创建更改密码功能...但我不知道为什么会收到错误,尽管我输入了正确的密码。它总是返回失败

我遵循此代码 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();
                    }
                }
            });

1 个答案:

答案 0 :(得分:1)

获取密码的代码不正确:

String pass = edtOldPass.getEditText().toString();

TextInputLayout上调用getEditText()会返回包含EditText窗口小部件,而不是EditText的字符串值。

将其更改为:

String pass = edtOldPass.getEditText().getText().toString();