예제 #1
0
        public int Register(string username, string password, byte[] hwid, string key) // Require a key on activation to prevent spam
        {
            try
            {
                if (Array.Exists(File.ReadAllLines("BannedHWIDs.txt"), x => x == Encoding.UTF8.GetString(hwid)))
                {
                    return(clsResults.BANNED);
                }

                clsKeys     keys    = frmMain.ReadXML <clsKeys>("keys.xml");
                clsKeyEntry thisKey = keys.lKeys.Find(x => x.sKey == key);

                if (thisKey == default(clsKeyEntry))
                {
                    return(clsResults.INVALID_KEY);
                }

                if (File.Exists(string.Format("Clients\\{0}.xml", username)))
                {
                    return(clsResults.ERR_USER_EXISTS);
                }

                clsClient  client      = new clsClient();
                clsUsedKey thisUsedKey = new clsUsedKey()
                {
                    sKey = thisKey.sKey, iValidFor = thisKey.iValidFor, dtActivation = DateTime.Now
                };
                client.sUsername = username;
                client.bHWID     = hwid;
                client.lHistory  = new List <clsUsedKey>();
                client.lHistory.Add(thisUsedKey);
                client.bPassword = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(password));

                isLoggedIn = true;
                isExpired  = false;
                thisClient = client;

                keys.lKeys.Remove(thisKey);
                this.thisKey = thisUsedKey;

                lock (frmMain.xmlLock)
                    frmMain.WriteXML(keys, "keys.xml");

                UpdateInfo();

                return(frmMain.WriteXML(client, string.Format("Clients\\{0}.xml", username)) ? clsResults.SUCCESS : clsResults.UNKNOWN_ERROR);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
                return(clsResults.UNKNOWN_ERROR);
            }
        }
예제 #2
0
        public int Login(string username, string password, byte[] hwid)
        {
            try
            {
                if (Array.Exists(File.ReadAllLines("BannedHWIDs.txt"), x => x == Encoding.UTF8.GetString(hwid)))
                {
                    return(clsResults.BANNED);
                }

                if (isLoggedIn)
                {
                    if (isExpired)
                    {
                        return(clsResults.SUCCESS_EXPIRED);
                    }
                    else
                    {
                        return(clsResults.SUCCESS);
                    }
                }

                if (!File.Exists(string.Format("Clients\\{0}.xml", username)))
                {
                    return(clsResults.INVALID_USERNAME);
                }

                clsClient client = frmMain.ReadXML <clsClient>(string.Format("Clients\\{0}.xml", username));

                if (!SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(password)).SequenceEqual(client.bPassword))
                {
                    return(clsResults.INVALID_PASSWORD);
                }

                if (!hwid.SequenceEqual(client.bHWID))
                {
                    return(clsResults.HWID_MISMATCH);
                }

                isLoggedIn = true;
                thisClient = client;

                foreach (clsUsedKey uKey in client.lHistory)
                {
                    if (DateTime.Now.CompareTo(uKey.dtActivation.Add(new TimeSpan(uKey.iValidFor, 0, 0, 0))) <= 0)
                    {
                        isExpired = false;
                        thisKey   = uKey;
                        UpdateInfo();
                        return(clsResults.SUCCESS);
                    }
                }

                isExpired = true;
                UpdateInfo();
                return(clsResults.SUCCESS_EXPIRED);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
                return(clsResults.UNKNOWN_ERROR);
            }
        }