Beispiel #1
0
 public static string generateToken(string userName)
 {
     try
     {
         var token = AESManager.Encrypt(JsonConvert.SerializeObject(new { UserName = userName, ExpirationDate = DateTime.Now.AddDays(10) }));
         return(token);
     }
     catch (Exception) { return(null); }
 }
Beispiel #2
0
 public static bool validateToken(string token)
 {
     try
     {
         var securityToken = JsonConvert.DeserializeObject <dynamic>(AESManager.Decrypt(token));
         if (securityToken == null)
         {
             return(false);
         }
         else
         {
             return(DateTime.Parse(securityToken.ExpirationDate.ToString()) > DateTime.Now);
         }
     }
     catch (Exception) { return(false); }
 }