简体   繁体   English

FirebaseUser 密码未通过 android 中的 updatePassword() 方法更新

[英]FirebaseUser password not updating through updatePassword() method in android

I am trying to update or reset the user's password in my Android application using Firebase Authentication.我正在尝试使用 Firebase 身份验证在我的 Android 应用程序中更新或重置用户密码。 For this, I am using the updatePassword() method provided by FirebaseUser class, but it is throwing the code in addOnFailureListener() and I am unable to figure out why.为此,我使用了 FirebaseUser class 提供的 updatePassword() 方法,但它在 addOnFailureListener() 中抛出了代码,我无法弄清楚原因。 please help me.请帮我。 I have provided the code to update the password below:我在下面提供了更新密码的代码:

updatePasswordButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String newPassword = enterPasswordEditText.getText().toString().trim();
                String confirmPassword = confirmPasswordEditText.getText().toString().trim();

                if (!newPassword.equals(confirmPassword)) {
                    Toast.makeText(EditProfileActivity.this, "Passwords don't match!", Toast.LENGTH_SHORT)
                            .show();
                } else {
                    //Updating password
                    firebaseUser.updatePassword(newPassword)
                            .addOnSuccessListener(new OnSuccessListener<Void>() {
                                @Override
                                public void onSuccess(Void unused) {
                                    Toast.makeText(EditProfileActivity.this, "Password changed successfully", Toast.LENGTH_SHORT)
                                            .show();
                                }
                            })
                            .addOnFailureListener(new OnFailureListener() {
                                @Override
                                public void onFailure(@NonNull Exception e) {
                                    Toast.makeText(EditProfileActivity.this, "Error in changing password", Toast.LENGTH_SHORT)
                                            .show();
                                }
                            });
                }
            }
        });

You're getting the following error:您收到以下错误:

Error in changing password: This operation is sensitive and requires recent authentication.更改密码时出错:此操作很敏感,需要最近的身份验证。 Log in again before retrying this request在重试此请求之前再次登录

Because changing the password is considered a sensitive operation.因为更改密码被认为是敏感操作。 This means that in order to perform that operation, Firebase requires that the user has recently signed in.这意味着为了执行该操作,Firebase 要求用户最近登录。

If the user hasn't recently signed in, meaning that 5 minutes have already passed, when you try to perform such a sensitive operation, Firebase throws an exception that contains the error message from above.如果用户最近没有登录,这意味着已经过去了 5 分钟,当您尝试执行此类敏感操作时,Firebase 会抛出包含上述错误消息的异常。

The simplest solution for this situation would be to ask the user to re-enter their credentials and retry the operation.对于这种情况,最简单的解决方案是要求用户重新输入他们的凭据并重试该操作。

Here is the official documentation for FirebaseAuthRecentLoginRequiredException .这是FirebaseAuthRecentLoginRequiredException的官方文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM