Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 238
Tamim Attafi Avatar asked Dec 20 '17 16:12

Tamim Attafi


1 Answers

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("[email protected]", "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.");
        }
    });
like image 155
Frank van Puffelen Avatar answered Sep 22 '22 20:09

Frank van Puffelen