Example #1
0
        private bool ValidateLicense(string _pathLicense)
        {
            BUS.CommonControl ctr  = new CommonControl();
            object            data = ctr.executeScalar(@"SELECT SUN_DATA  FROM SSINSTAL WHERE INS_TB='LCS' and INS_KEY='QD'");

            if (data != null)//File.Exists(_pathLicense.Replace("file:\\", ""))
            {
                //StreamReader reader = new StreamReader(_pathLicense);
                //string result = reader.ReadLine();
                string      kq      = RC2.DecryptString(data.ToString(), Form_QD._key, Form_QD._iv, Form_QD._padMode, Form_QD._opMode);
                string[]    tmp     = kq.Split(';');
                DTO.License license = new DTO.License();
                license.CompanyName  = tmp[0];
                license.ExpiryDate   = Convert.ToInt32(tmp[1]);
                license.Modules      = tmp[2];
                license.NumUsers     = Convert.ToInt32(tmp[3]);
                license.SerialNumber = tmp[4];
                license.Key          = tmp[5];
                //license.SerialCPU = tmp[6];
                //BUS.CommonControl ctr = new BUS.CommonControl();
                license.SerialCPU = ctr.executeScalar(@"SELECT   CONVERT(varchar(200), SERVERPROPERTY('servername'))").ToString(); //"BFEBFBFF000006FD";
                //reader.Close();


                string param = license.CompanyName + license.SerialNumber + license.NumUsers.ToString() + license.Modules + license.ExpiryDate.ToString() + license.SerialCPU;


                string temp = RC2.EncryptString(param, Form_QD._key, Form_QD._iv, Form_QD._padMode, Form_QD._opMode);
                string key  = Convert.ToBase64String(new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash(Encoding.ASCII.GetBytes(temp)));
                if (key == license.Key)
                {
                    int now = Convert.ToInt32(DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString("00") + DateTime.Now.Day.ToString("00"));
                    //BUS.CommonControl ctr = new CommonControl();
                    object dt = ctr.executeScalar("select getdate()", _strConnect);
                    if (dt != null && dt is DateTime)
                    {
                        now = Convert.ToInt32(((DateTime)dt).Year.ToString() + ((DateTime)dt).Month.ToString("00") + ((DateTime)dt).Day.ToString("00"));
                    }
                    if (now > license.ExpiryDate)
                    {
                        _sErr = "Your license is expired!";
                    }
                    else
                    {
                        //if (license.Modules.Length == 4 && license.Modules.Substring(3) == "Y")
                        return(true);
                        //else _flagQDADD = false;
                    }
                }
                else
                {
                    _sErr = "Application have not license!";
                }
            }
            else
            {
                _sErr = "Application have not license!";
            }
            return(false);
        }