title: How to set key validated time in c#
body: <p>I'm generating key using c# and send it among the user by mail. This part I was able to do.
  I want to set key validated time. When the key validate time is expire it not work. How can I do this?</p>
  
  <p>Key Generate and send it by mail</p>
  
  <pre><code>    public IHttpActionResult SendMail()
      {
          string mailBodyhtml = KeyGenerator.GetUniqueKey();
          var msg = new MailMessage("from@gmail.com", "to1@gmail.com", "Hello", mailBodyhtml);
          msg.To.Add("tomail@gmail.com");
          msg.IsBodyHtml = true;
          var smtpClient = new SmtpClient("smtp.gmail.com", 587); //if your from email address is "from@hotmail.com" then host should be "smtp.hotmail.com"**
          smtpClient.UseDefaultCredentials = true;
          smtpClient.Credentials = new NetworkCredential("abc@gmail.com", "#######");
          smtpClient.EnableSsl = true;
          smtpClient.Send(msg);
          Console.WriteLine("Email Sended Successfully");
          return Ok("Send Mail");
      }
  
  
  public class KeyGenerator
  {
      public static string GetUniqueKey()
      {
          int size = 6;
          char[] chars =
              "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".ToCharArray();
          byte[] data = new byte[size];
          using (RNGCryptoServiceProvider crypto = new RNGCryptoServiceProvider())
          {
              crypto.GetBytes(data);
          }
          StringBuilder result = new StringBuilder(size);
          foreach (byte b in data)
          {
              result.Append(chars[b % (chars.Length)]);
          }
          return result.ToString();
      }
  }
  </code></pre>