示例#1
0
        // Check the registry for valid date and serial number
        public static bool CheckSerialNumberRegistry(string productName, string productSerialRegistry)
        {
            string   nextDateCheck = CommonAttributes.LoadFromRegistry(CommonAttributes.RegNewDate);
            DateTime RegKeyDate;

            nextDateCheck = Encryption.Decrypt(nextDateCheck);
            try
            {
                RegKeyDate = DateTime.ParseExact(nextDateCheck, "yyyyMMdd", System.Globalization.CultureInfo.GetCultureInfo("en-US"));
            }
            catch (Exception)
            {
                MessageBox.Show("Please provide Internet connection for validating your product");
                return(false);
            }
            if ((RegKeyDate <= DateTime.Now) || (nextDateCheck == string.Empty) || (nextDateCheck == null))
            {
                MessageBox.Show("Please provide Internet connection for validating your product");
                return(false);
            }

            // TO DO: check for trial period

            string serialNumber = CommonAttributes.LoadSNFromRegistry(productSerialRegistry);

            if (serialNumber == null) // In case of missing registry entry
            {
                MessageBox.Show("Corrupted installation found. Please reinstall " + productName + "!");
                return(false);
            }

            // Trial mode or invalid serial number
            if ((serialNumber == "0") || (serialNumber == string.Empty))
            {
                // Displays the trial message once a day
                DisplayTrialMessage(productName, productSerialRegistry);
            }
            // If everything is ok program loading continues
            return(true);
        }
示例#2
0
 public static string GetUserInfoElement(RegCustInd index)
 {
     return(CommonAttributes.LoadFromRegistry(RegIfnoCustomer[(int)index]));
 }
示例#3
0
        public static void CheckProgramState(string ProductID, string SerialNumberIn,
                                             string RegSerialField, string ProductName, out Boolean AllowRun, out Boolean IsRegistered)
        {
            // cadbest.com/en/key.php?id=213&data2=1231321&.... - sample for parsing parameteres to the url
            try
            {
                string userID, serialNumber;
                string encrProductID, encrUserID, encrSerialNum;

                // Get the serial number of C:\
                userID = GetUserID();
                // Get the serial number from registry if is not provided
                if (string.IsNullOrEmpty(SerialNumberIn))
                {
                    // From registry serial number is already encrypted
                    serialNumber = CommonAttributes.LoadSNFromRegistry(RegSerialField);
                }
                else
                {
                    // When is passed from About or other module, it is not encrypted
                    serialNumber = SerialNumberIn;
                }

                //Encrypt the data
                encrProductID = Encryption.Encrypt(ProductID, 150);
                encrUserID    = Encryption.Encrypt(userID, 200);
                encrSerialNum = Encryption.Encrypt(serialNumber, 250);

                using (WebClient client = new WebClient())
                {
                    string responseStr;
                    NameValueCollection data = new NameValueCollection();
#if DEBUG
                    data[Parameter[0]] = encrUserID;
                    data[Parameter[1]] = encrSerialNum;
                    data[Parameter[2]] = encrProductID;
#else
                    data[Parameter[0]] = encrUserID;
                    data[Parameter[1]] = encrSerialNum;
                    data[Parameter[2]] = encrProductID;
#endif
                    // Send and recieve from the authorization url
                    Byte[] response = client.UploadValues(AuthURL.ToString(), "POST", data);
                    responseStr = System.Text.Encoding.UTF8.GetString(response);
                    // Replace <br /> with \n for proper work of StringReader
                    responseStr = responseStr.Replace("<br />", "\n");

                    // Reads the response string line by line
                    using (StringReader reader = new StringReader(responseStr))
                    {
                        string line;
                        //Initializing
                        AllowRun     = false;
                        IsRegistered = false;
                        // Read "Should run" responce
                        line = reader.ReadLine();

#if DEBUG
                        // Check if the response string contains backslash
                        if (line.Contains("\\"))
                        {
                            MessageBox.Show("Response contains backslash\n" + line);
                        }
#endif

                        if (line != null)
                        {
                            DateTime nextCheck;
                            line = Encryption.Decrypt(line);
                            if (line[0] == SHOULDRUN)
                            {
                                AllowRun = true;
                            }
                            if (line[1] == ISREGISTERED)
                            {
                                IsRegistered = true;
                            }

                            if (AllowRun && IsRegistered) // Product works for 30 days
                            {
                                nextCheck = DateTime.Now.AddDays(30);
                                CommonAttributes.SaveNextDateReg(nextCheck);
                            }
                            // Product works in trial mode for 3 days until next check
                            else if (AllowRun && !IsRegistered)
                            {
                                nextCheck = DateTime.Now.AddDays(3);
                                CommonAttributes.SaveNextDateReg(nextCheck);
                                if ((SerialNumberIn == string.Empty) || (SerialNumberIn == null))
                                {
                                    OfflineAuthorization.DisplayTrialMessage(ProductName, RegSerialField);
                                }
                            }
                            else if (!AllowRun) // The product is not registered and trial is over
                            {
#if DEBUG
                                using (StreamWriter fsParams = File.AppendText("C:\\params.txt"))
                                {
                                    fsParams.WriteLine(string.Format("{0} = {1} = {2}", Parameter[0], encrUserID, userID));
                                    fsParams.WriteLine(string.Format("{0} = {1} = {2}", Parameter[1], encrSerialNum, serialNumber));
                                    fsParams.WriteLine(string.Format("{0} = {1} = {2}", Parameter[2], encrProductID, ProductID));
                                    fsParams.WriteLine();
                                }
#endif
                                // Delete the corresponding registry, so program will not run next time in offline mode
                                CommonAttributes.DelKeyRegistry(CommonAttributes.RegNewDate);
                                // If any serial number was get from registry, which is validated as wrong,
                                // set the registry to "0", which means trial and allows entering a correct serial number
                                if ((SerialNumberIn == string.Empty) || (SerialNumberIn == null))
                                {
                                    CommonAttributes.SaveToRegistry(RegSerialField, "0");
                                }
                            }
                        }
                        else
                        {
                            throw new GetResponceException();
                        }

                        // Reading of user data if is returned
                        while ((line = reader.ReadLine()) != null)
                        {
                            string fieldDelimiter, field;
                            int    positionField;
                            fieldDelimiter = line.Substring(1, 2); // The delimiter which must be ::
                            field          = line.Substring(3);    // The remaining text
                            try
                            {
                                //positionField = int.Parse(String.Format("{0}", line[0]));
                                positionField = int.Parse(line.Substring(0, 1)); // The first character must be digit
                                if ((positionField >= 1) && (positionField <= 5) && (fieldDelimiter == "::"))
                                {
                                    CommonAttributes.SaveToRegistry(RegIfnoCustomer[positionField - 1], field);
                                }
                            }
                            catch (FormatException) // If the first symbol is not a digit, do nothing
                            {
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
                AllowRun     = false;
                IsRegistered = false;
            }
        }
示例#4
0
 public void SaveInstalledDateRegistry()
 {
     CommonAttributes.SaveInstalledDateRegistry();
 }