Custom Verification Code/Token in Asp .Net Identit

2019-09-13 01:31发布

问题:

I need to create short code (6 digits) for Email Confirmation using Asp.Net Identity. Currently, if I use

"GenerateEmailConfirmationTokenAsync" 

it provides me with very long code instead of this I want to generate a code which is only 6 digit in length. Is there any way to achieve this how can I extend identity to provide such a feature. any leads towards this will be helpful.

Thanks

回答1:

Yes you can. Check this SO answer for details.

Basically you have to create a class inheriting IUserTokenProvider<TUser, TKey> and implement those two methods: GenerateAsync and ValidateAsync.

There you will write the code to generate and validate your six characther token. The same token will be used everywhere inside the ASP.NET Identity without any other code change.