示例#1
0
        protected virtual bool ExtractClientInfo(ref LicenseInfo Client, string key)
        {
            string code = DeInterleave(key);
              if (code == null)
            {
                m_errorMsg = "Invalid key length.";
                Client.Clear();
                return false;
            }
            if (code.Length != m_codeLength)
            {
                //this should never be reached, but was added while debugging
                m_errorMsg = "Invalid code length.";
                Client.Clear();
                return false;
            }
            int version = AlphaDecode(key.Substring(0, 1)); //first character of the key is always the version
            if (version != m_version)
            {
                m_errorMsg = "Invalid license key.";
                Client.Clear();
                return false;
            }

            //character 0 was the version, 1 is tier, 2 & 3 are toolFlags
            Client.tier = AlphaDecode(code.Substring(1, 1));
            Client.toolFlags = (byte)AlphaDecode(code.Substring(2, 2));
            Client.clientAlias = UnMangleClientAliasAlpha(code.Substring(4));

            SetTierMaximums(ref Client);
            Client.key = key;

            return true;
        }
示例#2
0
        private bool ValidateClient(ref LicenseInfo Client, string clientAlias, string key)
        {
            if (!CleanText(ref clientAlias, m_clientAliasLength)) return false;

            if (!ExtractClientInfo(ref Client, key)) return false;//fill client info from the provided key

            //recalculate the key using the provided clientAlias
            string calcKey = CalcLicenseKey(clientAlias, Client.tier, Client.toolFlags);

            //compare client IDs and keys
            //string tempID = clientAlias.Substring(0, Client.clientAlias.Length); //Not needed because of clean...
            if ((!calcKey.Equals(key)) || (!clientAlias.Equals(Client.clientAlias)))
            {
                m_errorMsg = "Invalid key or client ID.";
                //invalid clients are disabled, but left in list, so keep client ID...
                Client.Clear();
                Client.clientAlias = clientAlias;
                return false;
            }
            //Check to see if this client can use this tool
            if (!IsToolAllowed(Client, ToolType))
            {
                m_errorMsg = "License is not authorized for this product.";
                Client.isValid = false;
                //key is valid in general, just not for this tool, so leave toolFlags etc alone
                return false;
            }

            Client.isValid = true;
            return true;
        }
示例#3
0
        public LicenseInfo GetLicenseInfo(string clientAlias)
        {
            LicenseInfo Client = new LicenseInfo();
            Client.Clear(); //empty client response will signal error

            int index = GetLicenseIndex(clientAlias);
            if (index < 0) //unable to find client in list;
            {
                //error message compiled in GetLicenseIndex
                return Client;
            }
            // invalid clients are disabled, but left in list, so need to check here...
            if (!m_clientList[index].isValid) //invalid client (bad key or not authorized for this tool)
            {
                //error message compiled in GetLicenseIndex
                return Client;
            }

            //valid client
            Client.Copy(m_clientList[index]);
            Client.key = ""; //do not release the key externally
            return Client;
        }