Ejemplo n.º 1
0
 public int Login(string message)
 {
     Login lg = new Login(message);
     Account targetAcct = Account.LoadAccount(lg.userName);
     if(targetAcct == null)
     {
         return -1;
     }
     if (targetAcct.Authenticate(lg.password))
     {
         targetAcct.Address = (OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty).Address;
         return Account.GetSessionId(lg.userName);
     }
     return -1;
 }
Ejemplo n.º 2
0
        public static int ClientLogin(string userName, string password)
        {
            password = Encryption.GetSha256Hash(password);
            Login lg = new Login();
            lg.userName = userName;
            lg.password = Encryption.GetSha256Hash(password + userName + DateTime.UtcNow.Day + DateTime.UtcNow.Month + DateTime.UtcNow.Year);

            try
            {
                string wrURI = baseServerTarget + "login";
                string msg = lg.ToString();
                WebRequest wreq = WebRequest.Create(wrURI + "?message=" + msg);
                wreq.Method = "POST";
                wreq.ContentLength = 0;
                WebResponse wresp = wreq.GetResponse();
                using (TextReader sr = new StreamReader(wresp.GetResponseStream()))
                {
                    XmlSerializer xml = new XmlSerializer(typeof(int), StringNamespace);
                    int resp = (int)xml.Deserialize(sr);
                    SessionId = resp;
                    UserId = userName;
                    if(Worker != null)
                    {
                        Worker.CancelAsync();
                        Worker.Dispose();
                        Worker = null;
                    }
                    if (SessionId != -1)
                    {
                        Worker = new BackgroundWorker();
                        Worker.DoWork += Worker_DoWork;
                        Worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
                        Worker.WorkerSupportsCancellation = true;
                        Worker.RunWorkerAsync();
                    }
                    return resp;
                }
            }
            catch
            {
                return -1;
            }
        }