Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dears,

I am handling user reset password in my APP and i am using the following code:

if the user clicks forget password, system generates token by the following code:
C#
var token = manager.GeneratePasswordResetToken(userId);


Generated token sent to user email with a link to update his new password.

if the token is verified using the following code:
C#
UserManager.VerifyUserToken(UserId, "ResetPassword", token)


the user update his password.
C#
UserManager.ResetPassword(user.Id, model.token, model.Password)


Now what if the user generated more than one token?
The current behavior, Any token opened will disable the other tokens. this is handled by ASP.net Identity.

I want disable all previous generated tokens while generating a new token. IS THIS APPLICAPLE?

What I have tried:

Generate a table for and saved all tokens. it works fine but i am looking for a better solution auto generated by ASP.NET Identity.
Posted
Updated 30-Dec-20 22:58pm
v2

Ummm.... You just said that you want to "disable all previous generated tokens while generating a new token", but that's exactly what you said the "current behavior" already does, "Any token opened will disable the other tokens".
 
Share this answer
 
Comments
_ProgProg_ 21-Jan-19 0:47am    
The current behavior is:
You can generate many tokens, but when you use one of them for resetting, the others are disabled. I want to disable all previous while generating new.
Dave Kreskowiak 21-Jan-19 16:51pm    
Why would you want to?
_ProgProg_ 22-Jan-19 0:32am    
Now i save all tokens in a DB Table then i am validating only the latest one. But if there is a way to get all tokens using identity with each token date that will be better.
Dave Kreskowiak 22-Jan-19 16:42pm    
How is that "better" and for who?
The default UserTokenProvider generates tokens based on the users's SecurityStamp, so until that changes(like when the user's password changes), the tokens will always be the same, and remain valid.

So if you want to simply invalidate old tokens, just call:

manager.UpdateSecurityStampAsync(user);
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900