简体   繁体   English

Asp .Net Identity中的自定义验证代码/令牌

[英]Custom Verification Code/Token in Asp .Net Identity

I need to create short code (6 digits) for Email Confirmation using Asp.Net Identity. 我需要使用Asp.Net Identity创建用于电子邮件确认的短代码(6位数字)。 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. 它为我提供了很长的代码,而不是我想生成的代码只有6位数字。 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 谢谢

Yes you can. 是的你可以。 Check this SO answer for details. 检查 SO答案以获取详细信息。

Basically you have to create a class inheriting IUserTokenProvider<TUser, TKey> and implement those two methods: GenerateAsync and ValidateAsync . 基本上,您必须创建一个继承IUserTokenProvider<TUser, TKey>的类IUserTokenProvider<TUser, TKey>并实现这两个方法: GenerateAsyncValidateAsync

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. 相同的令牌将在ASP.NET标识内的任何地方使用,而无需任何其他代码更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM