Sabbi
Sabbi

Reputation: 141

ASP.NET MVC Identity - how to change format of generated Token in SMS

Using the two factor authentification in ASP.NET MVC / Identity, I successfully set up the UserManager.SmsService.

By default, ASP.NET Identity generates a 6 digit long verification token which is sent by SMS. However, our requirement is to have a 4 characters long alphanumeric token instead.

The code is generated with this command:

var code = await UserManager.GenerateChangePhoneNumberTokenAsync(User.Identity.GetUserId(), phoneNumber);

Is there a way to define the format of the generated code?

Upvotes: 4

Views: 1158

Answers (1)

Nader Gharibian Fard
Nader Gharibian Fard

Reputation: 8135

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.

Upvotes: 0

Related Questions