コード例 #1
0
        public int ActivateKey(string key)
        {
            if (isLoggedIn == false || thisClient == default(clsClient))
            {
                return(clsResults.UNKNOWN_ERROR);
            }

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

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

            thisClient.lHistory.Add(new clsUsedKey()
            {
                sKey = thisKey.sKey, iValidFor = thisKey.iValidFor, dtActivation = DateTime.Now
            });
            keys.lKeys.Remove(thisKey);

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

            return(clsResults.SUCCESS);
        }
コード例 #2
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);
            }
        }