Click here to Skip to main content
15,943,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to implement a registration prozess for my webapp. I am using this process for generating a EmailConfirmationToken and sending it via email to the user.

C#
if (result.Succeeded)
 {
     string code = await userManager.GenerateEmailConfirmationTokenAsync(user.Id);
     Uri baseUri = new Uri(OpenIdConnectAuthenticationAuthority);
     Uri callbackUrl = new Uri(baseUri + "/Register/ConfirmEmail/?userId=" + user.Id + "&code=" + HttpUtility.UrlEncode(code));
     await userManager.SendEmailAsync(user.Id, "BIMcube eMail Confirmation", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
 }


The generated token is very long. This is a example token:

XML
AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAA48Afnm/pyU6UZrt2VXGfHAAAAAACAAAAAAADZgAAwAAAABAAAABa10013CpPZN7NSwTZYu03AAAAAASAAACgAAAAEAAAAHFDDmUWdvgFz4QCqe0ML/1gAAAAN7hpoCFiW8NcTaMNCGMLALUYL0gcfXbPjXQddI5w68mm4FfbVhMkJPbL+JTA8RXZ7mb6VgNmxS/cxdMzy5BQdIdVUIWzQYPwBlX6Oimx+zESVcCSpUSVpwI05+ls79nmFAAAAPTqCR7RSVR5zQT3UaJlcd1BokRr


My UserTokenProvider is implemented like this:
C#
var dataProtectionProvider = new DpapiDataProtectionProvider("IdentityServer3");

        if (dataProtectionProvider != null)
        {
            UserTokenProvider = new DataProtectorTokenProvider<User>(dataProtectionProvider.Create("ASP.NET Identity"))
            {
                TokenLifespan = TimeSpan.FromHours(3)
            };
        }


Is there any possibility for generating a short code for email confirmation? Do you have an idea what I need to implement?
Posted

1 solution

For unique token create GUID

string strToken = Convert.ToBase64String(Guid.NewGuid().ToByteArray());

Or you can use date time time stamp and generate token.
byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary());
byte[] key = Guid.NewGuid().ToByteArray();
string token = Convert.ToBase64String(time.Concat(key).ToArray());
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900