I just realized that when I press the forgot password in my app and change the password the password is not changed in the realtime database.Is it possible to change the realtime database as well? This is my forgot password page code
public class ForgotPassword extends AppCompatActivity { EditText useremail; Button password; FirebaseAuth auth; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_forgot_password); useremail=findViewById(R.id.enterEmailAddress); password=findViewById(R.id.sendpassword); auth=FirebaseAuth.getInstance(); password.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { auth.sendPasswordResetEmail(useremail.getText().toString()).addOnCompleteListener(new OnCompleteListener<Void>() { @Override public void onComplete(@NonNull Task<Void> task) { if(task.isSuccessful()){ Toast.makeText(ForgotPassword.this,"Password sent to your mail",Toast.LENGTH_LONG).show(); } else{ Toast.makeText(ForgotPassword.this,task.getException().getMessage(),Toast.LENGTH_LONG).show(); } } }); } }); } }
this is the value stored in my database
{ "Users" : { "Driver" : { "S04QBZx3PxYaLfDWBC3j3otM5ml1" : { "mail" : "m.yusuf7423@gmail.com", "password" : "1234567", "username" : "YUSUF" } } } }
Advertisement
Answer
Firebase Authentication doesn’t store the user credentials in the Firebase database.
If the user credentials are stored in the database, it’s because your application code stores it there. You will need to update it in the database by running the same code as you ran when you saved the credentials in the database initially.
Something like this could for example update the password:
FirebaseDatabase.getInstance().getReference("Users/Driver") .child(uid).child("password").setValue("new password");
Note: it is a really bad idea to store the user’s credentials in clear text like you’re doing, and I highly recommend leaving it to Firebase Authentication to store that data securely for you.