Firebase Authentication : how to get current user's Password?

北战南征 提交于 2020-08-24 08:22:39

问题


i'm new to firebase Authentication.. so, i'm creating a basic app with a profile, i've made an activity to edit basic informations of the user such as DisplayName and Email... , i wan't to add the capability of changing passwords, but first , i wan't to check current user's password and compare it to a String from an InputEditText that the user must know his current password before changing it.

EDIT : the thing i'm asking about is i ask the user to write his current Password in order to be able to change it to a new one to reduce hacking or something like that, like on Facebook when you're trying to change the Email or Password or even the Name it asks you for your current Password.

![Example


回答1:


From the Firebase documentation:

Some security-sensitive actions—such as deleting an account, setting a primary email address, and changing a password—require that the user has recently signed in.

If you perform one of these actions, and the user signed in too long ago, the action fails and throws FirebaseAuthRecentLoginRequiredException. When this happens, re-authenticate the user by getting new sign-in credentials from the user and passing the credentials to reauthenticate. For example:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

// Get auth credentials from the user for re-authentication. The example below shows
// email and password credentials but there are multiple possible providers,
// such as GoogleAuthProvider or FacebookAuthProvider.
AuthCredential credential = EmailAuthProvider
    .getCredential("user@example.com", "password1234");
// Prompt the user to re-provide their sign-in credentials
user.reauthenticate(credential)
    .addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            Log.d(TAG, "User re-authenticated.");
        }
    });


来源:https://stackoverflow.com/questions/47910898/firebase-authentication-how-to-get-current-users-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!