Ejemplo n.º 1
0
 public string getMockToken()
 {
     AuthenticationInstance ai = new AuthenticationInstance();
     ai.UserName = "******";
     ai.PassWord = "******";
     ai.TimeStamp = 1;
     return AuthenticationUtil.GenCookieToken(ai);
 }
Ejemplo n.º 2
0
 static void Main(string[] args)
 {
     AuthenticationInstance ai = new AuthenticationInstance();
     ai.UserName = "******";
     ai.PassWord = "******";
     ai.TimeStamp = 1;
     string token=AuthenticationUtil.GenCookieToken(ai);
     AuthenticationUtil.Verify(token);
 }
Ejemplo n.º 3
0
        public string getMockToken()
        {
            AuthenticationInstance ai = new AuthenticationInstance();

            ai.UserName  = "******";
            ai.PassWord  = "******";
            ai.TimeStamp = 1;
            return(AuthenticationUtil.GenCookieToken(ai));
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            AuthenticationInstance ai = new AuthenticationInstance();

            ai.UserName  = "******";
            ai.PassWord  = "******";
            ai.TimeStamp = 1;
            string token = AuthenticationUtil.GenCookieToken(ai);

            AuthenticationUtil.Verify(token);
        }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }