Exemplo n.º 1
0
        private void btnComputer_Click(object sender, EventArgs e)
        {
            string computerName = HardwareInfoHelper.GetComputerName();
            string userName     = HardwareInfoHelper.GetUserName();
            string systemType   = HardwareInfoHelper.GetSystemType();
            string cpuid        = HardwareInfoHelper.GetCPUId();
            string cpuName      = HardwareInfoHelper.GetCPUName();
            int    cpuUsage     = HardwareInfoHelper.GetCpuUsage();
            string diskId       = HardwareInfoHelper.GetDiskID();
            string ip           = HardwareInfoHelper.GetIPAddress();
            string macAddress   = HardwareInfoHelper.GetMacAddress();
            string memery       = HardwareInfoHelper.GetTotalPhysicalMemory();

            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("ComputerName:\t {0} \r\n", computerName);
            sb.AppendFormat("UserName:\t {0} \r\n", userName);
            sb.AppendFormat("SystemType:\t {0} \r\n", systemType);
            sb.AppendFormat("CPU ID:\t {0} \r\n", cpuid);
            sb.AppendFormat("CPU Name:\t {0} \r\n", cpuName);
            sb.AppendFormat("CPU Usage:\t {0} \r\n", cpuUsage);
            sb.AppendFormat("Disk Id:\t {0} \r\n", diskId);
            sb.AppendFormat("IP:\t {0} \r\n", ip);
            sb.AppendFormat("MacAddress:\t {0} \r\n", macAddress);
            sb.AppendFormat("TotalPhysicalMemory:\t {0} \r\n", memery);
            MessageDxUtil.ShowTips(sb.ToString());

            string identity = FingerprintHelper.Value();

            MessageDxUtil.ShowTips(identity);
        }
Exemplo n.º 2
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            #region 输入验证
            if (this.txtRePassword.Text != this.txtPassword.Text)
            {
                MessageDxUtil.ShowTips("两个新密码的输入不一致");
                this.txtRePassword.Focus();
                return;
            }
            #endregion

            try
            {
                string ip      = NetworkUtil.GetLocalIP();
                string macAddr = HardwareInfoHelper.GetMacAddress();
                bool   result  = BLLFactory <User> .Instance.ModifyPassword(this.LoginUserInfo.Name, this.txtPassword.Text, Portal.gc.SystemType, ip, macAddr);

                if (result)
                {
                    this.DialogResult = DialogResult.OK;
                    MessageDxUtil.ShowTips("密码修改成功");
                }
                else
                {
                    MessageDxUtil.ShowWarning("用户密码资料不正确,请核对");
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(FrmModifyPassword));
                MessageDxUtil.ShowError(ex.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     调用非对称加密方式对序列号进行验证
        /// </summary>
        /// <param name="serialNumber">正确的序列号</param>
        /// <returns>如果成功返回True,否则为False</returns>
        public RegisterResult Register(string serialNumber)
        {
            var result     = new RegisterResult();
            var hardNumber = HardwareInfoHelper.GetCpuId();

            try
            {
                var str2 = EncodeHelper.DesDecrypt(serialNumber);
                if (!string.IsNullOrEmpty(str2))
                {
                    var encrytedString = str2.Split('|')[0];
                    var time           = Convert.ToDateTime(EncodeHelper.DesDecrypt(str2.Split('|')[1]));
                    var flag2          = RsaSecurityHelper.Validate(hardNumber, encrytedString);
                    var flag           = time.AddDays(1.0) > DateTime.Now;
                    result.IsValid  = flag2 && flag;
                    result.ValideTo = time;
                    return(result);
                }
            }
            catch
            {
                // ignored
            }
            return(result);
        }
        public async Task <License> CreateLicense(Entities.License license, string customerName, string contactEmail)
        {
            var additionalAttributes = new Dictionary <string, string>
            {
                { nameof(license.Name), license.Name },
                { nameof(license.CreatedBy), license.CreatedBy },
                { nameof(license.DateFrom), license.DateFrom.ToString() },
                { nameof(license.HardwareId), HardwareInfoHelper.EncryptHardwareId(license.HardwareId) },
                { nameof(license.Active), license.Active.ToString() },
                { LicenseConstants.LicenseDbIdAttributeName, license.Id.ToString() }
            };

            var productFeatures = new Dictionary <string, string>
            {
                { nameof(license.NumberOfConcurrentUserSessionsAllowed), license.NumberOfConcurrentUserSessionsAllowed.ToString() },
            };

            return(License.New()
                   .WithUniqueIdentifier(Guid.NewGuid())
                   .As(LicenseType.Trial)
                   .ExpiresAt(license.DateTo)
                   .WithMaximumUtilization(license.NumberOfConcurrentUserSessionsAllowed)
                   .WithProductFeatures(productFeatures)
                   .WithAdditionalAttributes(additionalAttributes)
                   .LicensedTo(customerName, contactEmail)
                   .CreateAndSignWithPrivateKey(await this.licenseKeyService.GetPrivateKey(), LicenseConstants.PassPhrase));
        }
Exemplo n.º 5
0
        private void menu_InitPassword_Click(object sender, EventArgs e)
        {
            if (!HasFunction("User/Set/UserInitPwd"))
            {
                MessageDxUtil.ShowError(Const.NoAuthMsg);
                return;
            }

            if (MessageDxUtil.ShowYesNoAndTips(string.Format("您确定重置选定记录的用户密码么? \r\n重置后密码将设置为【{0}】", Const.defaultPwd)) == DialogResult.No)
            {
                return;
            }

            int[] rowSelected = this.winGridViewPager1.GridView1.GetSelectedRows();
            foreach (int iRow in rowSelected)
            {
                string ip           = NetworkUtil.GetLocalIP();
                string macAddr      = HardwareInfoHelper.GetMacAddress();
                Int32  changeUserId = this.winGridViewPager1.GridView1.GetRowCellDisplayText(iRow, "Id").ToInt32();

                bool success = BLLFactory <User> .Instance.ResetPassword(Portal.gc.UserInfo.Id, changeUserId, Portal.gc.SYSTEMTYPEID, ip, macAddr);

                MessageDxUtil.ShowTips(success ? "重置密码操作成功" : "操作失败");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 返回注册码信息 (用公钥生成)
        /// </summary>
        /// <returns></returns>
        public static string GetRegistrationCode(string userName, string Company)
        {
            string machineCode = HardwareInfoHelper.GetCPUId();
            string expireDate  = Convert.ToDateTime(Data.getSysDate()).AddYears(1).ToString("yyyy-MM-dd");
            string publicKey   = Const.publicKey;

            return(RSASecurityHelper.RSAEncrypt(publicKey, machineCode + Const.VerticalLine + expireDate + Const.VerticalLine + Company + Const.VerticalLine + userName));
        }
Exemplo n.º 7
0
        private void btLogin_Click(object sender, EventArgs e)
        {
            #region 检查验证
            if (this.cmbzhanhao.Text.Length == 0)
            {
                MessageDxUtil.ShowTips("请输入帐号");
                this.cmbzhanhao.Focus();
                return;
            }
            #endregion

            try
            {
                string ip        = NetworkUtil.GetLocalIP();
                string macAddr   = HardwareInfoHelper.GetMacAddress();
                string loginName = this.cmbzhanhao.Text.Trim();
                string identity  = BLLFactory <WHC.Security.BLL.User> .Instance.VerifyUser(loginName, this.tbPass.Text, "WareMis", ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = BLLFactory <WHC.Security.BLL.User> .Instance.GetUserByName(loginName);

                    #region 获取用户的功能列表

                    List <FunctionInfo> list = BLLFactory <WHC.Security.BLL.Function> .Instance.GetFunctionsByUser(info.ID, "WareMis");

                    if (list != null && list.Count > 0)
                    {
                        foreach (FunctionInfo functionInfo in list)
                        {
                            if (!Portal.gc.FunctionDict.ContainsKey(functionInfo.ControlID))
                            {
                                Portal.gc.FunctionDict.Add(functionInfo.ControlID, functionInfo);
                            }
                        }
                    }

                    #endregion

                    //登录成功
                    bLogin = true;
                    Portal.gc.LoginInfo = info;
                    this.DialogResult   = DialogResult.OK;
                }
                else
                {
                    MessageDxUtil.ShowTips("用户帐号密码不正确");
                    this.tbPass.Text = ""; //设置密码为空
                }
            }
            catch (Exception err)
            {
                MessageDxUtil.ShowError(err.Message);
            }
        }
        private static bool CheckHardwareId(License license)
        {
            // TODO: Export this string value.
            var licenseHardwareId = license.AdditionalAttributes.Get("HardwareId");

            if (string.IsNullOrEmpty(licenseHardwareId))
            {
                return(false);
            }

            return(HardwareInfoHelper.ValidateHardwareId(licenseHardwareId));
        }
Exemplo n.º 9
0
 /// <summary>
 /// 获取本地硬件信息
 /// </summary>
 public void GetPlayerInfo()
 {
     _PlayerInfo                  = new ClientInfo();
     _PlayerInfo.client_id        = HardwareInfoHelper.GetCPUSN();
     client_id                    = _PlayerInfo.client_id;
     _PlayerInfo.computer_name    = Environment.MachineName;
     _PlayerInfo.system_info      = HardwareInfoHelper.GetOS_Version();
     _PlayerInfo.ip_address       = HardwareInfoHelper.GetMachineIp();
     _PlayerInfo.bios_info        = HardwareInfoHelper.GetBiosInfo();
     _PlayerInfo.brand_info       = HardwareInfoHelper.GetBoardInfo();
     _PlayerInfo.cpu_info         = HardwareInfoHelper.GetCPUInfo();
     _PlayerInfo.screen_count     = HardwareInfoHelper.GetScreenCount();
     _PlayerInfo.memory_size      = HardwareInfoHelper.GetPhisicalMemory();
     _PlayerInfo.software_version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
     _PlayerInfo.online_status    = (int)ClientStatusEnum.OnLine;
 }
Exemplo n.º 10
0
        /// <summary>
        /// 重置用户密码为12345678
        /// </summary>
        /// <param name="id">用户ID</param>
        /// <returns></returns>
        public ActionResult ResetPassword(string id)
        {
            CommonResult result = new CommonResult();

            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    result.ErrorMessage = "用户id不能为空";
                }
                else
                {
                    UserInfo info = BLLFactory <User> .Instance.FindByID(id);

                    if (info != null)
                    {
                        string defaultPassword = Const.defaultPwd;
                        string ip       = NetworkUtil.GetLocalIP();
                        string macAddr  = HardwareInfoHelper.GetMacAddress();
                        bool   tempBool = BLLFactory <User> .Instance.ModifyPassword(info.Name, defaultPassword, Const.SystemTypeID, ip, macAddr);

                        if (tempBool)
                        {
                            result.Success = true;
                        }
                        else
                        {
                            result.ErrorMessage = "口令初始化失败";
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(UserController));
                result.ErrorMessage = ex.Message;
            }
            return(ToJsonContent(result));
        }
Exemplo n.º 11
0
        /// <summary>
        /// 修改用户密码
        /// </summary>
        /// <param name="name">用户名称</param>
        /// <param name="oldpass">旧密码</param>
        /// <param name="newpass">修改密码</param>
        /// <returns></returns>
        public ActionResult ModifyPass(string name, string oldpass, string newpass)
        {
            CommonResult result = new CommonResult();

            try
            {
                // TODO 这里要修改为Request IP
                string ip       = NetworkUtil.GetLocalIP();
                string macAddr  = HardwareInfoHelper.GetMacAddress();
                string identity = BLLFactory <User> .Instance.VerifyUser(name, oldpass, Const.SystemTypeID, ip, macAddr);

                if (string.IsNullOrEmpty(identity))
                {
                    result.ErrorMessage = "原口令错误";
                }
                else
                {
                    bool tempBool = BLLFactory <User> .Instance.ModifyPassword(name, newpass, Const.SystemTypeID, ip, macAddr);

                    if (tempBool)
                    {
                        result.Success = true;
                    }
                    else
                    {
                        result.ErrorMessage = "口令修改失败";
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(UserController));
                result.ErrorMessage = ex.Message;
            }
            return(ToJsonContent(result));
        }
Exemplo n.º 12
0
 public void OnGet()
 {
     HardwareId = HardwareInfoHelper.GenerateHardwareId();
 }
Exemplo n.º 13
0
        private void btnTestLogin_Click(object sender, EventArgs e)
        {
            if (this.txtLogin.Text.Trim() == "")
            {
                MessageDxUtil.ShowTips("请输入帐号");
                this.txtLogin.Focus();
                return;
            }

            try
            {
                //判断用户是否登录成功
                string loginName  = this.txtLogin.Text.Trim();
                string ip         = NetworkUtil.GetLocalIP();
                string macAddr    = HardwareInfoHelper.GetMacAddress();
                string systemType = "WareMis";
                string identity   = BLLFactory <User> .Instance.VerifyUser(loginName, this.txtPassword.Text, systemType, ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = BLLFactory <User> .Instance.GetUserByName(loginName);

                    if (info != null)
                    {
                        //获取该登陆用户的权限集合
                        List <FunctionInfo> list = BLLFactory <Functions> .Instance.GetFunctionsByUser(info.ID, systemType);

                        if (list != null && list.Count > 0)
                        {
                            foreach (FunctionInfo functionInfo in list)
                            {
                                if (!functionDict.ContainsKey(functionInfo.FunctionId))
                                {
                                    functionDict.Add(functionInfo.FunctionId, functionInfo);
                                }
                            }
                        }

                        //进一步判断用户角色
                        //if (BLLFactory<User>.Instance.UserIsAdmin(loginName))
                        //{
                        MessageDxUtil.ShowTips(string.Format("用户【{0}】身份验证正确", loginName));
                        //}
                        //else
                        //{
                        //    MessageDxUtil.ShowWarning("该用户没有管理员权限");
                        //    return;
                        //}
                    }
                }
                else
                {
                    MessageDxUtil.ShowWarning("用户名或密码错误");
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(Form1));
                MessageDxUtil.ShowError(ex.Message);
            }
        }
Exemplo n.º 14
0
 private string GetHardNumber()
 {
     return(HardwareInfoHelper.GetCPUId() + this.GetHexString(HardwareInfoHelper.GetCPUName()));
 }
Exemplo n.º 15
0
 /// <summary>
 /// 获取系统CPU序列号
 /// </summary>
 /// <returns></returns>
 public string GetCPUSerialID()
 {
     return(HardwareInfoHelper.GetCPUId());
 }
Exemplo n.º 16
0
        private void btLogin_Click(object sender, EventArgs e)
        {
            #region 检查验证
            if (Portal.gc.EnableRegister && !Portal.gc.Registed)
            {
                MessageUtil.ShowError("软件未进行授权注册,不能用于商业用途。\r\n如需注册,请单击左边【软件注册】按钮进行注册。");
            }

            if (this.cmbzhanhao.Text.Length == 0)
            {
                MessageDxUtil.ShowTips("请输入帐号");
                this.cmbzhanhao.Focus();
                return;
            }
            #endregion

            try
            {
                //保存用户登录参数
                SaveParameter();

                string ip        = NetworkUtil.GetLocalIP();
                string macAddr   = HardwareInfoHelper.GetMacAddress();
                string loginName = this.cmbzhanhao.Text.Trim();
                string identity  = CallerFactory <IUserService> .Instance.VerifyUser2(loginName, this.tbPass.Text, Portal.gc.SystemType, ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = CallerFactory <IUserService> .Instance.GetUserByName(loginName);

                    if (info != null)
                    {
                        #region 获取用户的功能列表

                        List <FunctionInfo> list = CallerFactory <IFunctionService> .Instance.GetFunctionsByUser(info.ID, Portal.gc.SystemType);

                        if (list != null && list.Count > 0)
                        {
                            foreach (FunctionInfo functionInfo in list)
                            {
                                if (!Portal.gc.FunctionDict.ContainsKey(functionInfo.ControlID))
                                {
                                    Portal.gc.FunctionDict.Add(functionInfo.ControlID, functionInfo.ControlID);
                                }
                            }
                        }

                        #endregion

                        #region 权限判断

                        //判断是否为超级管理员
                        Portal.gc.IsAdmin = CallerFactory <IUserService> .Instance.UserIsAdmin(info.Name);

                        //判断如果用户管理的公司数据多于一个,那么就显示选择单位列表,并绑定公司数据
                        Portal.gc.CompanyList = CallerFactory <IRoleDataService> .Instance.GetBelongCompanysByUser(info.ID);

                        List <int> deptList = CallerFactory <IRoleDataService> .Instance.GetBelongDeptsByUser(info.ID);

                        Portal.gc.DeptList = deptList;

                        //设置选定的公司ID(默认为用户所在公司的ID)
                        Cache.Instance["SelectedCompanyID"] = info.Company_ID;
                        //设置过滤条件给界面基类使用
                        string filterCondition = string.Format(" Company_ID = '{0}' ", info.Company_ID);
                        if (!Portal.gc.IsAdmin)
                        {
                            if (deptList.Count > 0)
                            {
                                filterCondition += string.Format(" AND Dept_ID IN ({0})", string.Join(",", deptList));
                            }
                            else
                            {
                                filterCondition += string.Format(" AND Creator = '{0}' ", info.ID);
                            }
                        }
                        Cache.Instance["DataFilterCondition"] = filterCondition;

                        #endregion

                        bLogin                  = true;
                        Portal.gc.UserInfo      = info;
                        Portal.gc.LoginUserInfo = Portal.gc.ConvertToLoginUser(info);
                        Cache.Instance.Add("LoginUserInfo", Portal.gc.LoginUserInfo); //缓存用户信息,方便后续处理
                        Cache.Instance.Add("FunctionDict", Portal.gc.FunctionDict);   //缓存权限信息,方便后续使用

                        this.DialogResult = DialogResult.OK;
                        RegistryHelper.SaveValue(Login_Name_Key, this.cmbzhanhao.Text);
                    }
                }
                else
                {
                    MessageDxUtil.ShowTips("用户帐号密码不正确");
                    this.tbPass.Text = ""; //设置密码为空
                }
            }
            catch (Exception ex)
            {
                LogTextHelper.Error(ex);
                MessageDxUtil.ShowError(ex.Message);
            }
        }
Exemplo n.º 17
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            #region 检查验证
            if (this.txtUserName.Text.Length == 0)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "请输入帐号", typeof(Login));
                MessageDxUtil.ShowError("请输入帐号");
                this.txtUserName.Focus();
                return;
            }

            if (this.txtPassword.Text.Length == 0)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "请输入密码", typeof(Login));
                MessageDxUtil.ShowError("请输入密码");
                this.txtPassword.Focus();
                return;
            }
            #endregion

            try
            {
                string loginName = this.txtUserName.Text.Trim();
                string ip        = NetworkUtil.GetLocalIP();
                string macAddr   = HardwareInfoHelper.GetMacAddress();
                string identity  = BLLFactory <User> .Instance.VerifyUser(loginName, this.txtPassword.Text, Portal.gc.SYSTEMTYPEID, ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = BLLFactory <User> .Instance.GetUserByName(loginName);

                    // 20191207 wjm 新增判断超级管理员 系统配置参数为1
                    // 20171109 wjm 不应该直接去判断这个Name的值,不合理 删除其逻辑判断
                    if (info != null && BLLFactory <Sysparameter> .Instance.UserIsSuperAdmin(loginName))
                    {
                        Portal.gc.UserInfo     = info;
                        Portal.gc.IsSuperAdmin = true;
                        bLogin            = true;
                        this.DialogResult = DialogResult.OK;
                    }
                    else if (info != null && BLLFactory <Role> .Instance.UserHasRole(info.Id))
                    {
                        Portal.gc.UserInfo     = info;
                        Portal.gc.IsSuperAdmin = false;
                        bLogin            = true;
                        this.DialogResult = DialogResult.OK;
                    }
                    else
                    {
                        LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, string.Format("该用户({0})没有管理员权限", loginName), typeof(Login));
                        MessageDxUtil.ShowError(string.Format("该用户({0})没有管理员权限", loginName));
                        txtUserName.Focus();
                        return;
                    }
                }
                else
                {
                    LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "用户名或密码错误或被禁止登陆", typeof(Login));
                    MessageDxUtil.ShowError("用户名或密码错误或被禁止登陆");
                    txtUserName.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(Login));
                MessageDxUtil.ShowError(ex.Message);
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// 使用参数化登录
        /// </summary>
        /// <param name="args"></param>
        private static void LoginByArgs(string[] args)
        {
            CommandArgs commandArgs = CommandLine.Parse(args);
            // 获取用户参数
            string loginName = commandArgs.ArgPairs["U"];
            string password  = commandArgs.ArgPairs.ContainsKey("P") ? commandArgs.ArgPairs["P"] : "";

            if (!string.IsNullOrEmpty(loginName))
            {
                string ip       = NetworkUtil.GetLocalIP();
                string macAddr  = HardwareInfoHelper.GetMacAddress();
                string identity = BLLFactory <WHC.Security.BLL.User> .Instance.VerifyUser(loginName, password, "WareMis", ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = BLLFactory <WHC.Security.BLL.User> .Instance.GetUserByName(loginName);

                    #region 获取用户的功能列表

                    List <FunctionInfo> list = BLLFactory <WHC.Security.BLL.Function> .Instance.GetFunctionsByUser(info.ID, "WareMis");

                    if (list != null && list.Count > 0)
                    {
                        foreach (FunctionInfo functionInfo in list)
                        {
                            if (!Portal.gc.FunctionDict.ContainsKey(functionInfo.ControlID))
                            {
                                Portal.gc.FunctionDict.Add(functionInfo.ControlID, functionInfo.ControlID);
                            }
                        }
                    }

                    #endregion

                    Portal.gc.UserInfo      = info;
                    Portal.gc.LoginUserInfo = Portal.gc.ConvertToLoginUser(info);
                    Cache.Instance.Add("LoginUserInfo", Portal.gc.LoginUserInfo); //缓存用户信息,方便后续处理
                    Cache.Instance.Add("FunctionDict", Portal.gc.FunctionDict);   //缓存权限信息,方便后续使用

                    #region 获取用户管理的库房
                    Portal.gc.ManagedWareHouse = Portal.gc.GetWareHouse(info);
                    if (Portal.gc.ManagedWareHouse != null && Portal.gc.ManagedWareHouse.Count > 0)
                    {
                        SplashScreen.Splasher.Show(typeof(SplashScreen.frmSplash));

                        gc.MainDialog = new MainForm();
                        gc.MainDialog.StartPosition = FormStartPosition.CenterScreen;
                        Application.Run(gc.MainDialog);
                    }
                    else
                    {
                        MessageUtil.ShowTips("用户登录信息正确,但未授权管理库房信息,请联系组长授权管理");
                        LoginNormal(args);
                    }

                    #endregion
                }
                else
                {
                    MessageUtil.ShowTips("用户帐号密码不正确");
                    LoginNormal(args);
                }
            }
            else
            {
                MessageUtil.ShowTips("命令格式有误");
                LoginNormal(args);
            }
        }
Exemplo n.º 19
0
        private void btLogin_Click(object sender, EventArgs e)
        {
            #region 检查验证
            if (Portal.gc.EnableRegister && !Portal.gc.Registed)
            {
                MessageUtil.ShowError("软件未进行授权注册,不能使用。\r\n请单击左边【软件注册】按钮进行注册。");
                return;
            }

            if (this.cmbzhanhao.Text.Length == 0)
            {
                MessageDxUtil.ShowTips("请输入帐号");
                this.cmbzhanhao.Focus();
                return;
            }
            #endregion

            try
            {
                string ip        = NetworkUtil.GetLocalIP();
                string macAddr   = HardwareInfoHelper.GetMacAddress();
                string loginName = this.cmbzhanhao.Text.Trim();
                string identity  = BLLFactory <WHC.Security.BLL.User> .Instance.VerifyUser(loginName, this.tbPass.Text, Portal.gc.SystemType, ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = BLLFactory <WHC.Security.BLL.User> .Instance.GetUserByName(loginName);

                    if (info != null)
                    {
                        #region 获取用户的功能列表

                        List <FunctionInfo> list = BLLFactory <WHC.Security.BLL.Function> .Instance.GetFunctionsByUser(info.ID, Portal.gc.SystemType);

                        if (list != null && list.Count > 0)
                        {
                            foreach (FunctionInfo functionInfo in list)
                            {
                                if (!Portal.gc.FunctionDict.ContainsKey(functionInfo.ControlID))
                                {
                                    Portal.gc.FunctionDict.Add(functionInfo.ControlID, functionInfo.ControlID);
                                }
                            }
                        }

                        #endregion

                        bLogin                  = true;
                        Portal.gc.UserInfo      = info;
                        Portal.gc.LoginUserInfo = Portal.gc.ConvertToLoginUser(info);
                        Cache.Instance.Add("LoginUserInfo", Portal.gc.LoginUserInfo); //缓存用户信息,方便后续处理
                        Cache.Instance.Add("FunctionDict", Portal.gc.FunctionDict);   //缓存权限信息,方便后续使用
                        Cache.Instance.Add("WeightModel", "自动");
                        this.DialogResult = DialogResult.OK;
                    }
                }
                else
                {
                    MessageDxUtil.ShowTips("用户帐号密码不正确");
                    this.tbPass.Text = ""; //设置密码为空
                }
            }
            catch (Exception err)
            {
                MessageDxUtil.ShowError(err.Message);
            }
        }
Exemplo n.º 20
0
 private void RegDlg_Load(object sender, EventArgs e)
 {
     txtMachineCode.Text = HardwareInfoHelper.GetCPUId();
 }
Exemplo n.º 21
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            #region 检查验证
            if (this.txtUserName.Text.Length == 0)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "请输入帐号", typeof(Login));
                MessageDxUtil.ShowError("请输入帐号");
                this.txtUserName.Focus();
                return;
            }

            if (this.txtPassword.Text.Length == 0)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "请输入密码", typeof(Login));
                MessageDxUtil.ShowError("请输入密码");
                this.txtPassword.Focus();
                return;
            }
            #endregion

            try
            {
                string ip        = NetworkUtil.GetLocalIP();
                string macAddr   = HardwareInfoHelper.GetMacAddress();
                string loginName = this.txtUserName.Text.Trim();

                string identity = BLLFactory <User> .Instance.VerifyUser(loginName, this.txtPassword.Text, Portal.gc.SystemType, ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    // 20171109 wjm 不应该直接去判断这个Name的值,不合理 删除其逻辑判断
                    //if (BLLFactory<User>.Instance.UserIsAdmin(loginName))
                    //{
                    UserInfo info = BLLFactory <User> .Instance.GetUserByName(loginName);

                    Portal.gc.UserInfo = info;                                      //赋值给全局变量“管理用户”
                    bLogin             = true;
                    this.DialogResult  = DialogResult.OK;
                    //}
                    //else
                    //{
                    //    LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "该用户没有管理员权限", typeof(Login));
                    //    MessageDxUtil.ShowError("该用户没有管理员权限");
                    //    txtUserName.Focus();
                    //    return;
                    //}
                }
                else
                {
                    LogHelper.WriteLog(LogLevel.LOG_LEVEL_ERR, "用户名或密码错误或被禁止登陆", typeof(Login));
                    MessageDxUtil.ShowError("用户名或密码错误或被禁止登陆");
                    txtUserName.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(Login));
                MessageDxUtil.ShowError(ex.Message);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// 调用非对称加密方式对序列号进行验证
        /// </summary>
        /// <param name="serialNumber">正确的序列号</param>
        /// <returns>如果成功返回True,否则为False</returns>
        public bool Register(String serialNumber)
        {
            string hardNumber = HardwareInfoHelper.GetCPUId();

            return(RSASecurityHelper.Validate(hardNumber, serialNumber));
        }
Exemplo n.º 23
0
        /// <summary>
        /// 处理登录
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btnLogin_Click(object sender, EventArgs e)
        {
            #region 检查验证
            if (this.txtUserName.Text.Length == 0)
            {
                MessageDxUtil.ShowTips("请输入帐号");
                this.txtUserName.Focus();
                return;
            }
            #endregion

            try
            {
                this.Cursor           = Cursors.WaitCursor;
                this.btnLogin.Enabled = false;
                this.btnExit.Enabled  = false;
                //保存用户登录参数
                SaveParameter();

                string ip        = NetworkUtil.GetLocalIP();
                string macAddr   = HardwareInfoHelper.GetMacAddress();
                string loginName = this.txtUserName.Text.Trim();
                string identity  = await CallerFactory <IUserService> .Instance.VerifyUser2Asyn(loginName, this.txtPassword.Text, Portal.gc.SystemType, ip, macAddr).TimeOut <string>(Portal.gc.AsynTimeOut);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = await CallerFactory <IUserService> .Instance.GetUserByNameAsyn(loginName).TimeOut <UserInfo>(Portal.gc.AsynTimeOut);

                    if (info != null)
                    {
                        #region 获取用户的功能列表
                        Portal.gc.FunctionDict.Clear();

                        List <FunctionInfo> list = await CallerFactory <IFunctionService> .Instance.GetFunctionsByUserAsyn(info.ID, Portal.gc.SystemType).TimeOut <List <FunctionInfo> >(Portal.gc.AsynTimeOut);

                        if (list != null && list.Count > 0)
                        {
                            foreach (FunctionInfo functionInfo in list)
                            {
                                if (!Portal.gc.FunctionDict.ContainsKey(functionInfo.ControlID))
                                {
                                    Portal.gc.FunctionDict.Add(functionInfo.ControlID, functionInfo.ControlID);
                                }
                            }
                        }


                        #endregion

                        #region 权限判断

                        //判断是否为超级管理员
                        Portal.gc.IsAdmin = await CallerFactory <IUserService> .Instance.UserIsAdminAsyn(info.Name).TimeOut <bool>(Portal.gc.AsynTimeOut);

                        //判断如果用户管理的公司数据多于一个,那么就显示选择单位列表,并绑定公司数据
                        Portal.gc.CompanyList = await CallerFactory <IRoleDataService> .Instance.GetBelongCompanysByUserAsyn(info.ID).TimeOut <List <string> >(Portal.gc.AsynTimeOut);

                        List <string> deptList = await CallerFactory <IRoleDataService> .Instance.GetBelongDeptsByUserAsyn(info.ID).TimeOut <List <string> >(Portal.gc.AsynTimeOut);

                        Portal.gc.DeptList = deptList;

                        //设置选定的公司ID(默认为用户所在公司的ID)
                        Cache.Instance["SelectedCompanyID"] = info.Company_ID;
                        //设置过滤条件给界面基类使用
                        string filterCondition = string.Format(" Company_ID = '{0}' ", info.Company_ID);
                        if (!Portal.gc.IsAdmin)
                        {
                            if (deptList.Count > 0)
                            {
                                filterCondition += string.Format(" AND Dept_ID IN ('{0}')", deptList.CreateSQLInCondition());
                            }
                            else
                            {
                                filterCondition += string.Format(" AND Creator = '{0}' ", info.ID);
                            }
                        }
                        Cache.Instance["DataFilterCondition"] = filterCondition;

                        #endregion

                        bLogin                        = true;
                        Portal.gc.UserInfo            = info;
                        Portal.gc.LoginUserInfo       = Portal.gc.ConvertToLoginUser(info); //方便后续处理
                        Portal.gc.LoginUserInfo.Data1 = txtPassword.Text;                   //当前用户登录密码,方便其他子系统自动登录
                        Cache.Instance.Add("FunctionDict", Portal.gc.FunctionDict);         //缓存权限信息,方便后续使用
                        Cache.Instance.Add("LoginUserInfo", Portal.gc.LoginUserInfo);

                        this.DialogResult = DialogResult.OK;
                        RegistryHelper.SaveValue(Login_Name_Key, this.txtUserName.Text);
                    }
                }
                else
                {
                    MessageDxUtil.ShowTips("用户帐号密码不正确");
                    this.txtPassword.Text = ""; //设置密码为空
                }
            }
            catch (Exception ex)
            {
                LogTextHelper.Error(ex);
                MessageDxUtil.ShowError(ex.Message);
            }
            finally
            {
                this.btnExit.Enabled  = true;
                this.btnLogin.Enabled = true;
                this.Cursor           = Cursors.Default;
            }
        }
Exemplo n.º 24
0
        /// <summary>
        /// 验证注册码信息(机器码|有效日期|注册公司|注册用户)
        /// </summary>
        /// <param name="encryptedString"> 注册码信息 </param>
        /// <returns>返回0 表示正确,-1表示注册码错误,-2表示机器码错误, -3表示注册已过期, -4表示其他内部错误, -5 注册人员信息错误,-6注册公司错误</returns>
        public static Int32 CheckRegistrationCode(string encryptedString, string struserName, string strcompany)
        {
            string originalString = null;

            try
            {
                originalString = RSASecurityHelper.RSADecrypt(Const.privateKey, encryptedString);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog(LogLevel.LOG_LEVEL_CRIT, ex, typeof(RSASecurityHelper));
                return(-1);
            }

            string[] d2 = originalString.Split('|');
            if (d2.Length != 4)
            {
                return(-4);
            }

            string machineCode = d2[0];
            string expireDate  = d2[1];
            string companyName = d2[2];
            string userName    = d2[3];

            if (!string.Equals(machineCode, HardwareInfoHelper.GetCPUId(), StringComparison.OrdinalIgnoreCase))
            {
                return(-2);
            }

            DateTime nowdt    = Convert.ToDateTime(Data.getSysDate());
            DateTime expiredt = Convert.ToDateTime(expireDate);

            if (nowdt > expiredt)
            {
                return(-3);
            }

            AppConfig config = Cache.Instance["AppConfig"] as AppConfig;

            if (config == null)
            {
                config = new AppConfig();
                Cache.Instance["AppConfig"] = config;
            }

            string LicensePath = config.AppConfigGet("LicensePath");

            if (!string.Equals(struserName, userName, StringComparison.OrdinalIgnoreCase))
            {
                return(-5);
            }
            if (!string.Equals(strcompany, companyName, StringComparison.OrdinalIgnoreCase))
            {
                return(-6);
            }

            RegistryKey reg;
            string      regkey = UIConstants.SoftwareRegistryKey;

            reg = Registry.CurrentUser.OpenSubKey(regkey, true);
            if (null == reg)
            {
                reg = Registry.CurrentUser.CreateSubKey(regkey);
            }
            if (null != reg)
            {
                reg.SetValue("productName", UIConstants.SoftwareProductName);
                reg.SetValue("version", UIConstants.SoftwareVersion);
                reg.SetValue("SysDate", expireDate);
                reg.SetValue("UserName", userName);
                reg.SetValue("Company", companyName);
                reg.SetValue("regCode", encryptedString);
            }

            // 写入lic 文件
            FileUtil.WriteText(LicensePath, encryptedString + Const.VerticalLine + userName + Const.VerticalLine + companyName, Encoding.Default);

            return(0);
        }
Exemplo n.º 25
0
 private string GetMachineCode()
 {
     return(HardwareInfoHelper.GetCPUId());
 }
Exemplo n.º 26
0
 public string GetHardNumber()
 {
     return(HardwareInfoHelper.GetCPUId());
 }
Exemplo n.º 27
0
 private void btnGetMachineCode_Click(object sender, EventArgs e)
 {
     txtMachineCode.Text = HardwareInfoHelper.GetCPUId();
 }
Exemplo n.º 28
0
 /// <summary>
 /// 初始化数据
 /// </summary>
 private void Init_View()
 {
     txtMachineCode.Text = HardwareInfoHelper.GetCPUId();
     txtExpiredDate.Text = DateTimeHelper.GetServerDateTime2().AddYears(1).ToString("yyyyMMdd");
 }
Exemplo n.º 29
0
        /// <summary>
        /// 对用户登录的操作进行验证
        /// </summary>
        /// <param name="username">用户账号</param>
        /// <param name="password">用户密码</param>
        /// <param name="code">验证码</param>
        /// <returns></returns>
        public ActionResult CheckUser(string username, string password, string code)
        {
            CommonResult result = new CommonResult();

            bool codeValidated = true;

            if (this.TempData["ValidateCode"] != null)
            {
                codeValidated = (this.TempData["ValidateCode"].ToString() == code);
            }

            if (string.IsNullOrEmpty(username))
            {
                result.ErrorMessage = "用户名不能为空";
            }
            else if (!codeValidated)
            {
                result.ErrorMessage = "验证码输入有误";
            }
            else
            {
                string ip       = NetworkUtil.GetLocalIP(); // TODO 这里要改成requestIP
                string macAddr  = HardwareInfoHelper.GetMacAddress();
                string identity = BLLFactory <User> .Instance.VerifyUser(username, password, Const.SystemTypeID, ip, macAddr);

                if (!string.IsNullOrEmpty(identity))
                {
                    UserInfo info = BLLFactory <User> .Instance.GetUserByName(username);

                    if (info != null)
                    {
                        result.Success = true;

                        //方便方法使用
                        Session["UserInfo"] = info;

                        Session["FullName"]   = info.FullName;
                        Session["UserID"]     = info.ID;
                        Session["Company_ID"] = info.Company_ID;
                        Session["Dept_ID"]    = info.Dept_ID;
                        bool isSuperAdmin = BLLFactory <User> .Instance.UserInRole(info.Name, RoleInfo.SuperAdminName);//判断是否超级管理员

                        Session["IsSuperAdmin"] = isSuperAdmin;

                        Session["Identity"] = info.Name.Trim();

                        #region 取得用户的授权信息,并存储在Session中

                        List <FunctionInfo> functionList = BLLFactory <Functions> .Instance.GetFunctionsByUser(info.ID, Const.SystemTypeID);

                        Dictionary <string, string> functionDict = new Dictionary <string, string>();
                        foreach (FunctionInfo functionInfo in functionList)
                        {
                            if (!string.IsNullOrEmpty(functionInfo.FunctionId) &&
                                !functionDict.ContainsKey(functionInfo.FunctionId))
                            {
                                functionDict.Add(functionInfo.FunctionId, functionInfo.Name);
                            }
                        }
                        Session["Functions"] = functionDict;

                        #endregion
                    }
                }
                else
                {
                    result.ErrorMessage = "用户名输入错误或者您已经被禁用";
                }
            }

            return(ToJsonContent(result));
        }