To update a user's password in Firebase Authentication you must re-authenticate : https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseUser#reauthenticate(com.google.firebase.auth.AuthCredential)
Yet this function does not seem to double check if the currentPassword
is correct before actually re-authenticating. I believe this may be because Firebase does not require re-authentication until after a set period of time, and will bypass this if it is still within that timeframe.
Here's what I have thus far:
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
AuthCredential credential = EmailAuthProvider
.getCredential(mAuth.getInstance().getCurrentUser().getEmail(), currentPass.getText().toString());
user.reauthenticate(credential)
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Log.d(TAG, "User re-authenticated.");
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
user.updatePassword(newPass1.getText().toString())
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
dialog.dismiss();
Toast.makeText(manageAccount.this, "Password updated!", Toast.LENGTH_LONG).show();
}else {
}
}
});
}
});
It seems that the currentPass
field can be equal to absolutely anything and the app will continue through and change the password. Is there a way in which you can force Firebase to actually check if the currentPass
is equal to the actual current password? Of course one way would be to save the password when first signing in within the client, but this would of course be very bad practice in security terms.
if (currentPass.getText().equals(newPass.getText()))
– Abhinav Chauhan