public static bool checkToken(string token, long customerNumber) { tokenTransactionService = new TokenTransactionService(); byte[] data = Convert.FromBase64String(token); DateTime when = DateTime.FromBinary(BitConverter.ToInt64(data, 0)); if (when < DateTime.UtcNow.AddMinutes(-4)) { TokenTransaction tt = new TokenTransaction(); tt = tokenTransactionService.SelectByCustomerNumber(customerNumber); tokenTransactionService.Delete(tt); return(false); } return(true); }
public static string CreateToken(long customerNumber) { tokenTransactionService = new TokenTransactionService(); byte[] time = BitConverter.GetBytes(DateTime.UtcNow.ToBinary()); byte[] key = Guid.NewGuid().ToByteArray(); string token = Convert.ToBase64String(time.Concat(key).ToArray()); TokenTransaction tt = new TokenTransaction { INSERT_USER = "******", UPDATE_USER = "******", CUSTOMER_NUMBER = customerNumber, TOKEN = token }; tokenTransactionService.Insert(tt); return(token); }