3

I'm using GenerateEmailConfirmationTokenAsync to generate token to confirm email. By default, it will generate a 6 digits, Ex: 534623. But end-user requirements wants it is 4 digits, Ex: 5346.

string code = await UserManager.GenerateChangePhoneNumberTokenAsync(user.Id);
/// I would like code variable is 4 digits

Then verify it at

var result = await UserManager.ChangePhoneNumberAsync(userId, code);
/// I would like to verify with 4 digits only

I searched and knew that I need to customize DataProtectorTokenProvider. But I did't find out how to customize it.

Thanks

Hieu Le
  • 1,042
  • 8
  • 18
  • Delete the unwanted digits? – tadman Sep 26 '17 at 03:36
  • @tadman I need 4 digits to verify later. I cannot delete it guy – Hieu Le Sep 26 '17 at 03:38
  • 1
    You sure can. You're given a string. Trim off the last two digits you told me you don't want. Figure out a way to save that updated code. – tadman Sep 26 '17 at 03:40
  • This 2 questions may provide the answer (or duplicate?) https://stackoverflow.com/questions/36963854/custom-verification-code-token-in-asp-net-identity and https://stackoverflow.com/questions/24994115/custom-email-confirmation-token – Prisoner Sep 26 '17 at 03:53
  • @Prisoner I already read those questions. But sorry, I don't know how to apply the answers to resolve my issue. I mean I would like more detail, such as a sample code – Hieu Le Sep 26 '17 at 03:56
  • @tadman you mean I can store 2 last digits and then append it to end-user's input? I think your suggestion is OK. But something, I don't have 2 last digits to append it. – Hieu Le Sep 26 '17 at 04:01
  • 1
    Either delete them and force it to save that truncated code, or when you do your validation only compare the first four. Either that or tell the powers that be that six digit codes are awesome and totally worth using! – tadman Sep 26 '17 at 04:02
  • @tadman these codes are never stored anywhere in the system - they are generated based on user information and generated second time to verify. Yes, one can save the last 2 digits, but that's getting into Rube Goldberg's territory – trailmax Sep 26 '17 at 22:56
  • @trailmax thanks, Do you have any suggestion for our? – Hieu Le Sep 27 '17 at 00:57
  • 1
    @hiule nothing simple/tested I can think of. I'd go back to my demanding customer and tell them that it can be done, but it'll take a lot of time/money due to the technical constraints in the framework. – trailmax Sep 27 '17 at 09:30

0 Answers0