Reputation:
How to find out that the user has changed the password or not via mail. I am registering user with email
mAuth.createUserWithEmailAndPassword(id, pass);
and if user asks for forgot password i send forgot email by
mAuth.sendPasswordResetEmail(email);
But I cannot say or figure it out that the user has changed it via email or not?
How is it possible to figure out that the password is changed or not via email?
Upvotes: 4
Views: 1756
Reputation: 13129
You can attach a complete listener to sendPasswordResetEmail()
, and if the email has been sent, you can write in your database inside that user ID a value that will tell you that the password has been reset.
If you need to check that the user has changed the password, you can check at your database whether the user did or not.
For example, a basic structure to check that the user has changed passwords could be this
- UserID
|__ passwordReset
|_____ passwordResetPushID
|___ changed : TIMESTAMP
...
Remember that FirebaseAuth getCurrentUser()
could be null at the time of changing the password if you are doing it from the login flow, but it's not going to be any problem if you do it inside your app after the user is logged in.
For the first case, you will need a little workaround, maybe storing into sharedPrefs
the latest user logged in ID.
As Frank's comments, you will need a sort of function that is triggered after the user has reset the password in the browser, this solution will only let you know whenever the sendPasswordResetEmail()
has been triggered but not a confirmation that the user has completed the password change, to do that, follow Frank's answer.
Upvotes: 1
Reputation: 5271
I faced the same case few days ago when I required to save user's password in my Database too. But when user change his password via Link it was difficult for me to get user's new changed password. So I did it in the following way
While signing in through App save user's password in SharedPreferences
after successful Firebase authentication. So you will always have latest user's password in your SharedPreferences. And now in your case to check user really changed his password or not, you can check if the password which is going to be saved on signin in SharedPreferences
is different from the previous one, Its mean it was changed.
Upvotes: 3
Reputation: 599641
If you want to detect whether the user clicked the link in the password reset email, consider setting up your own handler for the email actions. Have a look at the document for inspiration, or at the default page that is used when you don't provide a custom one.
Upvotes: 2