1

I am trying to implement a short code (6digits) for Email Confirmation using Asp.Net Identity Core.

Currently, I am using the existing implementation which is TotpSecurityStampBasedTokenProvider .

Everything works fine, it generates the 6 digit code that I want using this line of code var token = await _userManager.GenerateUserTokenAsync(user, "EmailTokenProvider", "EmailConfirmation"); ,

it also verifies if the code entered is valid or not using this method here var isValid = await _userManager.VerifyUserTokenAsync(user, "EmailTokenProvider", "EmailConfirmation", token);.

My problem is, when I am trying to call the method await _userManager.ConfirmEmailAsync(user, token); it says InvalidToken, do I need to implement my own ConfirmEmailAsync? As I also dig deep into it, it calls the SetEmailConfirmedAsync, do I also need to override the current implementation for that by creating my own custom IUserEmailStore?

Thanks!

Here are some of the sample references: Implement email confirmation with digit code, Custom Verification Code/Token in Asp .Net Identity

venalyn sudaria
  • 149
  • 1
  • 11
  • Could you share a little more code? Unfortunately the github link you posted 404's out for me. Things that come to mind: 1. It seems as though you are generating good tokens, do you save them down to a data store yourself or is there a package you are using that does this for you? 2. If this package didn't create tables for you to store the tokens, it is very likely you will have to write your own ConfirmEmailAsync function. – Ben Matthews Mar 23 '22 at 18:29
  • The link you provided is 404, So I can only make a simple judgment based on your question, In my opinion, this question may caused by `encode and decode of verification tokens`, So you can try to refer to this [link](https://stackoverflow.com/questions/25111928/invalid-token-while-verifying-email-verification-code-using-usermanager-confirm). – Xinran Shen Mar 24 '22 at 06:02

1 Answers1

0

Try this

var token = await _userManager.GenerateEmailConfirmationTokenAsync(user);

Instead of

var token = await _userManager.GenerateUserTokenAsync(user, "EmailTokenProvider", "EmailConfirmation");

Click Documentation

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 30 '23 at 12:48