BgEngine.Infraestructure.Security.CodeFirstCrypto.GenerateToken C# (CSharp) Метод

GenerateToken() статический приватный Метод

static private GenerateToken ( ) : string
Результат string
        internal static string GenerateToken()
        {
            byte[] tokenBytes = new byte[TOKEN_SIZE_IN_BYTES];
            using (RNGCryptoServiceProvider prng = new RNGCryptoServiceProvider())
            {
                prng.GetBytes(tokenBytes);
                return Convert.ToBase64String(tokenBytes);
            }
        }

Usage Example

 public override string GeneratePasswordResetToken(string userName, int tokenExpirationInMinutesFromNow)
 {
     if (string.IsNullOrEmpty(userName))
     {
         throw CreateArgumentNullOrEmptyException("userName");
     }
     using (BlogUnitOfWork context = new BlogUnitOfWork(new ModelContextInit()))
     {
         dynamic user = context.Users.FirstOrDefault(Usr => Usr.Username == userName);
         if (user == null)
         {
             throw new InvalidOperationException("El usuario no existe");
         }
         if (!user.IsConfirmed)
         {
             throw new InvalidOperationException("El usuario no existe");
         }
         string token = null;
         if (user.PasswordVerificationTokenExpirationDate > DateTime.UtcNow)
         {
             token = user.PasswordVerificationToken;
         }
         else
         {
             token = CodeFirstCrypto.GenerateToken();
         }
         user.PasswordVerificationToken = token;
         user.PasswordVerificationTokenExpirationDate = DateTime.UtcNow.AddMinutes(tokenExpirationInMinutesFromNow);
         context.SaveChanges();
         return(token);
     }
 }
All Usage Examples Of BgEngine.Infraestructure.Security.CodeFirstCrypto::GenerateToken