public string getMockToken() { AuthenticationInstance ai = new AuthenticationInstance(); ai.UserName = "******"; ai.PassWord = "******"; ai.TimeStamp = 1; return AuthenticationUtil.GenCookieToken(ai); }
static void Main(string[] args) { AuthenticationInstance ai = new AuthenticationInstance(); ai.UserName = "******"; ai.PassWord = "******"; ai.TimeStamp = 1; string token=AuthenticationUtil.GenCookieToken(ai); AuthenticationUtil.Verify(token); }
public string getMockToken() { AuthenticationInstance ai = new AuthenticationInstance(); ai.UserName = "******"; ai.PassWord = "******"; ai.TimeStamp = 1; return(AuthenticationUtil.GenCookieToken(ai)); }
public static bool Verify(string token) { string json = RSAUtil.Instance.Decrypt(token); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(AuthenticationInstance)); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)); AuthenticationInstance ai = ser.ReadObject(ms) as AuthenticationInstance; return(true); }
static void Main(string[] args) { AuthenticationInstance ai = new AuthenticationInstance(); ai.UserName = "******"; ai.PassWord = "******"; ai.TimeStamp = 1; string token = AuthenticationUtil.GenCookieToken(ai); AuthenticationUtil.Verify(token); }
public static string GenCookieToken(AuthenticationInstance instance) { MemoryStream stream1 = new MemoryStream(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(AuthenticationInstance)); ser.WriteObject(stream1, instance); stream1.Position = 0; StreamReader sr = new StreamReader(stream1); string instanceStr=sr.ReadToEnd(); string tokenGenerated=RSAUtil.Instance.Encrypt(instanceStr); return tokenGenerated; }
public static string GenCookieToken(AuthenticationInstance instance) { MemoryStream stream1 = new MemoryStream(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(AuthenticationInstance)); ser.WriteObject(stream1, instance); stream1.Position = 0; StreamReader sr = new StreamReader(stream1); string instanceStr = sr.ReadToEnd(); string tokenGenerated = RSAUtil.Instance.Encrypt(instanceStr); return(tokenGenerated); }
public string Authenticate(AuthenticationInstance ai) { EventLog log = new EventLog("MyEvent"); // 首先应判断日志来源是否存在,一个日志来源只能同时与一个事件绑定s if (!EventLog.SourceExists("New Application")) EventLog.CreateEventSource("New Application", "MyEvent"); log.Source = "New Application"; log.WriteEntry("authenticate:"+ai.UserName, EventLogEntryType.Information); log.WriteEntry("authenticate:"+ai.PassWord, EventLogEntryType.Information); Console.WriteLine(ai.UserName); Console.WriteLine(ai.PassWord); string token = AuthenticationUtil.GenCookieToken(ai); //AuthenticationUtil.Verify(token); return token; }
public string Authenticate(AuthenticationInstance ai) { EventLog log = new EventLog("MyEvent"); // 首先应判断日志来源是否存在,一个日志来源只能同时与一个事件绑定s if (!EventLog.SourceExists("New Application")) { EventLog.CreateEventSource("New Application", "MyEvent"); } log.Source = "New Application"; log.WriteEntry("authenticate:" + ai.UserName, EventLogEntryType.Information); log.WriteEntry("authenticate:" + ai.PassWord, EventLogEntryType.Information); Console.WriteLine(ai.UserName); Console.WriteLine(ai.PassWord); string token = AuthenticationUtil.GenCookieToken(ai); //AuthenticationUtil.Verify(token); return(token); }
public static bool Verify(string token) { EventLog log = new EventLog("MyEvent"); // 首先应判断日志来源是否存在,一个日志来源只能同时与一个事件绑定s if (!EventLog.SourceExists("New Application")) { EventLog.CreateEventSource("New Application", "MyEvent"); } log.Source = "New Application"; log.WriteEntry("verifying:" + token, EventLogEntryType.Information); string json = RSAUtil.Instance.Decrypt(token); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(AuthenticationInstance)); MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json)); AuthenticationInstance ai = ser.ReadObject(ms) as AuthenticationInstance; log.WriteEntry("verifying:" + ai.UserName, EventLogEntryType.Information); log.WriteEntry("verifying:" + ai.PassWord, EventLogEntryType.Information); return(true); }