Exemple #1
0
        //权限鉴定
        private static bool autoRight(AuthRightInfo authDataInfo)
        {
            string file;

            if (authDataInfo.SNFileName != null && authDataInfo.SNFileName.Length > 0)
            {
                file = MB.Util.General.GeApplicationDirectory() + authDataInfo.SNFileName + ".Txt";
            }
            else
            {
                file = MB.Util.General.GeApplicationDirectory() + @"UfAccreditSn.Txt";
            }
            //检验是否已经拥有了授权码

            try {
                System.IO.StreamReader read = new System.IO.StreamReader(file);
                string strTemp = read.ReadLine();
                read.Close();
                //	TraceEx.Write(strTemp);
                AuthRightInfo tempInfo = AuthDataRight(strTemp);
                if (tempInfo != null)
                {
                    authDataInfo.EndDate = tempInfo.EndDate;
                    DateTime curdate = System.DateTime.Now;
                    authDataInfo.LinkCount = tempInfo.LinkCount;
                    if (curdate >= authDataInfo.EndDate)
                    {
                        MessageBox.Show("授权码已经到期,请与软件供应商联系!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        authDataInfo.PassIsRight = false;
                    }
                    else
                    {
                        TimeSpan tPan = authDataInfo.EndDate.Subtract(curdate);

                        if (tPan.Days < MAX_SHOW_MSG)
                        {
                            MessageBox.Show("授权码 " + tPan.Days + " 天后到期,请与软件供应商联系!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }

                        authDataInfo.PassIsRight = true;
                    }
                }                //验证授权码是否正确
            }
            catch (Exception ee) {
                //UP.Utils.TraceEx.Write("启动监控获取相关数据出错." + ee.Message);
                authDataInfo.PassIsRight = false;
            }

            if (!authDataInfo.PassIsRight)
            {
                //启动授权码接受Form
                FrmAuthorization frm = new FrmAuthorization(authDataInfo);
                frm.BringToFront();
                frm.ShowDialog();
//				if (!authDataInfo.PassIsRight) {
//					MessageBox.Show("您没有正确的授权!,程序退出","操作提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
//				}
            }
            return(authDataInfo.PassIsRight);
        }
        //get KeyIn Accredit PassWord determine Right Or Wrong
        private void butSure_Click(object sender, System.EventArgs e)
        {
            try {
                string        sourceStr    = this.txtAuthNumber.Text;
                AuthRightInfo tempAuthInfo = AuthHelper.AuthDataRight(sourceStr);
                if (tempAuthInfo == null)
                {
                    MessageBox.Show("授权码错误!请与软件供应商联系!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    _RightData.PassIsRight = false;
                    return;
                }
                _RightData.PassIsRight = string.Compare(_SerNumber, tempAuthInfo.HardDC, true) == 0 && tempAuthInfo.EndDate > System.DateTime.Now;

                if (_RightData.PassIsRight)
                {
                    _RightData.EndDate   = tempAuthInfo.EndDate;
                    _RightData.LinkCount = tempAuthInfo.LinkCount;

                    MessageBox.Show("授权码正确!" + _RightData.ToString(), "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    //save accreditSn
                    string file;
                    if (_RightData.SNFileName != null && _RightData.SNFileName.Length > 0)
                    {
                        file = MB.Util.General.GeApplicationDirectory() + _RightData.SNFileName + ".Txt";
                    }
                    else
                    {
                        file = AppDomain.CurrentDomain.BaseDirectory + @"UfAccreditSn.Txt";
                    }
                    try {
                        StringBuilder sb = new StringBuilder();
                        if (System.IO.File.Exists(file))
                        {
                            System.IO.File.Delete(file);
                        }
                        sb.Append(sourceStr);
                        byte[]     bts = Encoding.UTF8.GetBytes(sb.ToString());
                        FileStream fs  = new FileStream(file, FileMode.CreateNew, FileAccess.Write);
                        fs.Write(bts, 0, bts.Length);
                        fs.Close();
                    }
                    catch (Exception ex) {
                        MessageBox.Show(ex.ToString());
                    }
                    this.Close();
                }
                else
                {
                    MessageBox.Show("授权码错误!请与软件供应商联系!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    _RightData.PassIsRight = false;
                }
            }
            catch {
                MessageBox.Show("授权码错误!请与软件供应商联系!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                _RightData.PassIsRight = false;
            }
        }
Exemple #3
0
        /// <summary>
        /// 系统系列号鉴定。
        /// </summary>
        /// <returns></returns>
        public static bool AuthRight(string privateName)
        {
            AuthRightInfo rightData = new AuthRightInfo();

            rightData.SNFileName = privateName;
            bool b = autoRight(rightData);

            return(b);
        }
Exemple #4
0
        /// <summary>
        /// 获取用户当前鉴权的信息。
        /// </summary>
        /// <param name="privateName"></param>
        /// <returns></returns>
        public static AuthRightInfo GetAuthInfo(string privateName)
        {
            //UP.Utils.TraceEx.Write("开始进行权限鉴定.....");
            AuthRightInfo rightData = new AuthRightInfo();

            rightData.SNFileName = privateName;
            bool b = autoRight(rightData);

            if (b)
            {
                return(rightData);
            }
            return(rightData);
        }
Exemple #5
0
        /// <summary>
        /// 鉴定并分析授权码字符窜。
        /// </summary>
        /// <param name="autoString"></param>
        /// <returns></returns>
        public static AuthRightInfo AuthDataRight(string autoString)
        {
            string descStr = AuthDataEncrypt.DescryptHDString(autoString);

            if (descStr == null || descStr.Length < 16)
            {
                return(null);
            }

            string endDate = AuthDataEncrypt.ToDec(descStr.Substring(descStr.Length - 5, 5)).ToString();

            descStr = descStr.Substring(0, descStr.Length - 5);

            string linkCount = AuthDataEncrypt.ToDec(descStr.Substring(descStr.Length - 5, 5)).ToString();

            descStr = descStr.Substring(0, descStr.Length - 5);
            AuthRightInfo autoInfo = new AuthRightInfo();

            autoInfo.EndDate   = DateTime.FromOADate(double.Parse(endDate));
            autoInfo.LinkCount = int.Parse(linkCount);
            autoInfo.HardDC    = descStr;

            return(autoInfo);
        }
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="pRightData"></param>
        public FrmAuthorization(AuthRightInfo pRightData)
        {
            InitializeComponent();

            _RightData = pRightData;
        }