public bool CheckToken(string token) { IList <string> keys = token.Split(":"); string date = CryptHelper.ToDecrypt(keys[2]); dynamic keysUser = new { email = CryptHelper.ToDecrypt(keys[0]), password = CryptHelper.ToDecrypt(keys[1]) }; dynamic loginValid = this.LoginUser(keysUser); if (loginValid != null) { DateTime now = CryptHelper.BrazilEast(DateTime.Now); DateTime tokenDate = Convert.ToDateTime(date); TimeSpan interval = now.Date - tokenDate.Date; if (interval.Days <= 3) { return(true); } else { throw new Exception("Token expired !"); } } else { throw new Exception("Token invalid !"); } }
public dynamic GenerateTokenUser(dynamic request) { User user = this.LoginUser(request); string key1 = (string)request.email; string key2 = (string)request.password; DateTime now = CryptHelper.BrazilEast(DateTime.Now); string key1Encrypted = CryptHelper.ToCrypt(key1); string key2Encrypted = CryptHelper.ToCrypt(key2); string nowEncrypted = CryptHelper.ToCrypt(now.ToString()); return(new { accessToken = key1Encrypted + ":" + key2Encrypted + ":" + nowEncrypted, userId = user.Id.ToString(), email = user.Email }); }