程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> 權限管理系統之軟件注冊模塊,權限管理系統

權限管理系統之軟件注冊模塊,權限管理系統

編輯:C#入門知識

權限管理系統之軟件注冊模塊,權限管理系統


轉自:http://www.cnblogs.com/jara/

軟件注冊是商業軟件必不可少的模塊,在整個程序中啟到舉足輕重的作用。

系統啟動時首先會檢測程序是否注冊,如果程序沒有注冊可以使用30次,試用次數完成後將彈出注冊界面。程序每次登陸都會將程序使用次數寫入到注冊表中,程序注冊是也會將注冊碼已加密的方式寫入到注冊表中。

復制代碼
   public static void RegMetod(bool isDownLoad)
        {
            try
            {
                SoftReg softReg = new SoftReg();
                //判斷軟件是否注冊
                RegistryKey retkey = Registry.CurrentUser.OpenSubKey("SOFTWARE", true).CreateSubKey(Encrypt.EncryptDES("mySoftWare", Const.EncryptKey)).CreateSubKey(Encrypt.EncryptDES("Register.INI", Const.EncryptKey));
                foreach (string strRNum in retkey.GetSubKeyNames())
                {
                    if (Encrypt.DecryptDES(strRNum, Const.EncryptKey) == softReg.GetRNum())
                    {
                        run(isDownLoad, "正式版", "");
                        return;
                    }
                }

                Int32 tLong;
                try
                {
                    tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Encrypt.EncryptDES("mySoftWare", Const.EncryptKey), "UseTimes", 0);
                }
                catch
                {
                    Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Encrypt.EncryptDES("mySoftWare", Const.EncryptKey), "UseTimes", 0, RegistryValueKind.DWord);
                }
                tLong = (Int32)Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Encrypt.EncryptDES("mySoftWare", Const.EncryptKey), "UseTimes", 0);
                if (tLong < 30)
                {
                    int tTimes = tLong + 1;
                    Registry.SetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\" + Encrypt.EncryptDES("mySoftWare", Const.EncryptKey), "UseTimes", tTimes);
                    int xint = 30 - tTimes;
                    //試用版不提供更新服務
                    run(true, "試用版", xint.ToString());
                }
                else
                {
                    DialogResult result = Comm.MessageBox.YesNo("試用次數已到!您是否需要注冊?");
                    if (result == DialogResult.Yes)
                    {
                        RegisterForm registerForm = new RegisterForm();
                        registerForm.ShowDialog();
                    }
                    else
                    {
                        Application.Exit();
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error("程序注冊出錯!");
                throw new Exception("程序注冊出錯:" + e.Message);
            }
        }
復制代碼

注冊界面:

復制代碼
        #region * 注冊
        private void btnReg_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtLicence.Text))
            {
                Client.Win.Comm.MessageBox.Info("注冊碼不能為空!");
                return;
            }
            try
            {
                if (txtLicence.Text == softReg.GetRNum())
                {
                    Client.Win.Comm.MessageBox.Info("注冊成功!重啟軟件後生效!");
                    RegistryKey retkey = Registry.CurrentUser.OpenSubKey("Software", true).CreateSubKey(Encrypt.EncryptDES("mySoftWare", Const.EncryptKey)).CreateSubKey(Encrypt.EncryptDES("Register.INI", Const.EncryptKey)).CreateSubKey(Encrypt.EncryptDES(txtLicence.Text, Const.EncryptKey));
                    retkey.SetValue(Encrypt.EncryptDES("UserName",Const.EncryptKey),Encrypt.EncryptDES( "Rsoft",Const.EncryptKey));
                    this.Close();
                }
                else
                {
                    Client.Win.Comm.MessageBox.Warn("注冊碼錯誤!");
                    txtLicence.SelectAll();
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        #endregion
復制代碼

生成機器碼(由MAC地址和硬盤券盤號截取前面20位):

復制代碼
     ///<summary>
        /// 生成機器碼
        ///</summary>
        ///<returns></returns>
        public string GetMNum()
        {
            string strNum = Computer.Instance().MacAddress + Computer.Instance().VolumeSerialNumber; // GetCpu() + GetDiskVolumeSerialNumber();
            string strMNum = string.Empty;
            if (strNum.Length > 20)
            {
                strMNum = strNum.Substring(0, 20);    //截取前20位作為機器碼
            }
            else
            {
                strMNum = strNum;
            }
            return strMNum;
        }
復制代碼

生成注冊碼:

復制代碼
        ///<summary>
        /// 生成注冊碼
        ///</summary>
        ///<returns></returns>
        public string GetRNum()
        {
            SetIntCode();
            string strMNum = GetMNum();
            for (int i = 1; i < charCode.Length; i++)   //存儲機器碼
            {
                charCode[i] = Convert.ToChar(strMNum.Substring(i - 1, 1));
            }
            for (int j = 1; j < intNumber.Length; j++)  //改變ASCII碼值
            {
                intNumber[j] = Convert.ToInt32(charCode[j]) + intCode[Convert.ToInt32(charCode[j])];
            }
            string strAsciiName = "";   //注冊碼
            for (int k = 1; k < intNumber.Length; k++)  //生成注冊碼
            {

                if ((intNumber[k] >= 48 && intNumber[k] <= 57) || (intNumber[k] >= 65 && intNumber[k]
                    <= 90) || (intNumber[k] >= 97 && intNumber[k] <= 122))  //判斷如果在0-9、A-Z、a-z之間
                {
                    strAsciiName += Convert.ToChar(intNumber[k]).ToString();
                }
                else if (intNumber[k] > 122)  //判斷如果大於z
                {
                    strAsciiName += Convert.ToChar(intNumber[k] - 10).ToString();
                }
                else
                {
                    strAsciiName += Convert.ToChar(intNumber[k] - 9).ToString();
                }
            }
            return strAsciiName;
        }
復制代碼

獲取電腦的基本信息:

復制代碼
 /// <summary>
    /// Computer Information
    /// </summary>
    public class Computer
    {
        public string CpuID;
        public string MacAddress;
        public string DiskID;
        public string IpAddress;
        public string LoginUserName;
        public string ComputerName;
        public string SystemType;
        public string TotalPhysicalMemory; //單位:M
        public string VolumeSerialNumber;
        private static Computer _instance;
        public static Computer Instance()
        {
            if (_instance == null)
                _instance = new Computer();
            return _instance;
        }
        protected Computer()
        {
            VolumeSerialNumber = GetDiskVolumeSerialNumber();
            CpuID = GetCpuID();
            MacAddress = GetMacAddress();
            DiskID = GetDiskID();
            IpAddress = GetIPAddress();
            LoginUserName = GetUserName();
            SystemType = GetSystemType();
            TotalPhysicalMemory = GetTotalPhysicalMemory();
            ComputerName = GetComputerName();
        }

        ///<summary>
        /// 獲取硬盤卷標號
        ///</summary>
        ///<returns></returns>
        public string GetDiskVolumeSerialNumber()
        {
            try
            {
                ManagementClass mc = new ManagementClass("win32_NetworkAdapterConfiguration");
                ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");
                disk.Get();
                return disk.GetPropertyValue("VolumeSerialNumber").ToString();
            }
            catch
            {
                return "unknow";
            }
            finally
            {
            }
        }

        /// <summary>
        /// CPU序列號
        /// </summary>
        /// <returns></returns>
        string GetCpuID()
        {
            //try
            //{
            //    //獲取CPU序列號代碼
            //    string cpuInfo = "";//cpu序列號
            //    ManagementClass mc = new ManagementClass("Win32_Processor");
            //    ManagementObjectCollection moc = mc.GetInstances();
            //    foreach (ManagementObject mo in moc)
            //    {
            //        cpuInfo = mo.Properties["ProcessorId"].Value.ToString();
            //    }
            //    moc = null;
            //    mc = null;
            //    return cpuInfo;
            //}
            //catch
            //{
            //    return  "unknow";
            //}
            //finally
            //{
            //}
            return "";
        }

        /// <summary>
        /// MAC地址
        /// </summary>
        /// <returns></returns>
        string GetMacAddress()
        {
            try
            {
                //獲取網卡Mac地址
                string mac = "";
                ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    if ((bool)mo["IPEnabled"] == true)
                    {
                        mac = mo["MacAddress"].ToString();
                        break;
                    }
                }
                moc = null;
                mc = null;
                return mac.Replace(":", "");
            }
            catch
            {
                return "unknow";
            }
            finally
            {
            }
        }

        /// <summary>
        /// IP地址
        /// </summary>
        /// <returns></returns>
        string GetIPAddress()
        {
            try
            {
                //獲取IP地址
                string st = "";
                ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    if ((bool)mo["IPEnabled"] == true)
                    {
                        //st=mo["IpAddress"].ToString();
                        System.Array ar;
                        ar = (System.Array)(mo.Properties["IpAddress"].Value);
                        st = ar.GetValue(0).ToString();
                        break;
                    }
                }
                moc = null;
                mc = null;
                return st;
            }
            catch
            {
                return "unknow";
            }
            finally
            {
            }
        }

        /// <summary>
        /// 硬盤序列號
        /// </summary>
        /// <returns></returns>
        string GetDiskID()
        {
            try
            {
                //獲取硬盤ID
                String HDid = "";
                ManagementClass mc = new ManagementClass("Win32_DiskDrive");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    HDid = (string)mo.Properties["Model"].Value;
                }
                moc = null;
                mc = null;
                return HDid;
            }
            catch
            {
                return "unknow";
            }
            finally
            {
            }

        }

        /// <summary>
        /// 操作系統的登錄用戶名
        /// </summary>
        /// <returns></returns>
        string GetUserName()
        {
            try
            {
                string st = "";
                ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    st = mo["UserName"].ToString();
                }
                moc = null;
                mc = null;
                return st;
            }
            catch
            {
                return "unknow";
            }
            finally
            {
            }
        }


        /// <summary>
        /// PC類型
        /// </summary>
        /// <returns></returns>
        string GetSystemType()
        {
            try
            {
                string st = "";
                ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {

                    st = mo["SystemType"].ToString();

                }
                moc = null;
                mc = null;
                return st;
            }
            catch
            {
                return "unknow";
            }
            finally
            {
            }
        }

        /// <summary>
        /// 物理內存
        /// </summary>
        /// <returns></returns>
        string GetTotalPhysicalMemory()
        {
            try
            {
                string st = "";
                ManagementClass mc = new ManagementClass("Win32_ComputerSystem");
                ManagementObjectCollection moc = mc.GetInstances();
                foreach (ManagementObject mo in moc)
                {
                    st = mo["TotalPhysicalMemory"].ToString();
                }
                moc = null;
                mc = null;
                return st;
            }
            catch
            {
                return "unknow";
            }
            finally
            {
            }
        }

        /// <summary>
        /// 計算機名稱
        /// </summary>
        /// <returns></returns>
        string GetComputerName()
        {
            try
            {
                return System.Environment.GetEnvironmentVariable("ComputerName");
            }
            catch
            {
                return "unknow";
            }
            finally
            {
            }
        }
復制代碼

完成以上即可實現軟件注冊!


您的手機無系統最高權限管理模塊(ROOT權限)

ROOT之後就可以獲取最高權限,舉個例子:你買了手機沒有ROOT限權只能玩些基本應用,如果你想把手機上不需要的系統軟件刪掉,比如系統自帶的舊版本UC,你是刪不掉的。如果你有ROOT權限,你就可以把它刪掉。系統為了保護這些功能的使用正常,(怕誤刪除)一般的官方系統是未ROOT的,但是有些軟件是需要ROOT的,如果你想更改系統的字體啊,第二屏動畫呀,修改某些系統設定呀。都是需要ROOT的,但是不能亂來的。簡單點就是:就是獲得管理員權限 你可以任意得改動系統文件 你在系統中擁有了絕對的權利 許多系統優化應用需要ROOT權限。關於安卓系統方面的知識你可以去機鋒論壇上多了解了解。
 

php模塊權限管理系統

一般的CMS都有這個模塊,單獨的系統倒是沒有
 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved