コード例 #1
0
    /// <summary>
    /// 保存Cookie
    /// </summary>
    /// <param name="userName">用户名</param>
    /// <param name="password">密码</param>
    public static void SaveCookie(string userName, string password)
    {
        password = SecretHelper.AESEncrypt(password);
        var httpCookie = new HttpCookie(Utils.CookieName);

        // httpCookie.Domain = "HairihanTECH";
        httpCookie.Values[Utils.CookieUserName] = userName;
        if (SystemInfo.RememberPassword)
        {
            httpCookie.Values[Utils.CookiePassword] = password;
        }
        // 设置过期时间为1天
        DateTime dateTime = DateTime.Now;

        httpCookie.Expires = dateTime.AddDays(30);
        HttpContext.Current.Response.Cookies.Add(httpCookie);
    }
コード例 #2
0
        public override bool SaveEntity()
        {
            var dbLinkEntity = new CiDbLinkDefineEntity
            {
                LinkName    = this.txtLinkName.Text.Trim(),
                LinkType    = this.cboLinkType.Text.Trim(),
                Enabled     = this.chkEnabled.Checked ? 1 : 0,
                DeleteMark  = 0,
                Description = this.txtDescription.Text.Trim()
            };
            string linkData = txtDbLinks.Text.Trim();

            dbLinkEntity.LinkData = SecretHelper.AESEncrypt(linkData);

            string statusMessage = string.Empty;
            string statusCode    = string.Empty;

            try
            {
                RDIFrameworkService.Instance.DbLinkDefineService.Add(base.UserInfo, dbLinkEntity, out statusCode, out statusMessage);
                if (statusCode == StatusCode.OKAdd.ToString())
                {
                    if (SystemInfo.ShowSuccessMsg)
                    {
                        MessageBoxHelper.ShowSuccessMsg(statusMessage);
                    }
                    return(true);
                }

                MessageBoxHelper.ShowWarningMsg(statusMessage);
                if (statusCode == StatusCode.ErrorNameExist.ToString())
                {
                    this.txtLinkName.SelectAll();
                }
                return(false);
            }
            catch (Exception ex)
            {
                base.ProcessException(ex);
                return(false);
            }
        }
コード例 #3
0
        private bool SaveEditData()
        {
            currentDblinkDefine.LinkName    = this.txtLinkName.Text.Trim();
            currentDblinkDefine.LinkType    = this.cboLinkType.Text.Trim();
            currentDblinkDefine.Enabled     = this.chkEnabled.Checked ? 1 : 0;
            currentDblinkDefine.DeleteMark  = 0;
            currentDblinkDefine.Description = this.txtDescription.Text.Trim();
            string linkData = txtDbLinks.Text.Trim();

            currentDblinkDefine.LinkData = SecretHelper.AESEncrypt(linkData);

            string statusMessage = string.Empty;
            string statusCode    = string.Empty;

            try
            {
                RDIFrameworkService.Instance.DbLinkDefineService.Update(base.UserInfo, currentDblinkDefine, out statusCode, out statusMessage);
                if (statusCode == StatusCode.OKUpdate.ToString())
                {
                    if (SystemInfo.ShowSuccessMsg)
                    {
                        MessageBoxHelper.ShowSuccessMsg(statusMessage);
                    }
                    return(true);
                }

                MessageBoxHelper.ShowWarningMsg(statusMessage);
                if (statusCode == StatusCode.ErrorNameExist.ToString())
                {
                    this.txtLinkName.SelectAll();
                }
                return(false);
            }
            catch (Exception ex)
            {
                base.ProcessException(ex);
                return(false);
            }
        }
コード例 #4
0
    /// <summary>
    /// 更新密码
    /// </summary>
    /// <param name="oldPassword">原密码</param>
    /// <param name="newPassword">新密码</param>
    /// <param name="statusCode">返回状态码</param>
    /// <returns>影响行数</returns>
    public static int ChangePassword(UserInfo userInfo, string oldPassword, string newPassword, out string statusCode)
    {
        int returnValue = 0;

        statusCode = string.Empty;
        // 新密码是否允许为空
        if (!SystemInfo.EnableCheckPasswordStrength)
        {
            if (String.IsNullOrEmpty(newPassword))
            {
                statusCode = StatusCode.PasswordCanNotBeNull.ToString();
                return(returnValue);
            }
        }
        // 是否加密
        oldPassword = SecretHelper.AESEncrypt(oldPassword);
        newPassword = SecretHelper.AESEncrypt(newPassword);

        // 判断输入原始密码是否正确
        // 密码错误
        if (!GetPassword(userInfo.Id).Equals(oldPassword))
        {
            statusCode = StatusCode.OldPasswordError.ToString();
            return(returnValue);
        }
        // 更改密码
        returnValue = SetPassword(userInfo.Id, newPassword);
        if (returnValue == 1)
        {
            statusCode = StatusCode.ChangePasswordOK.ToString();
        }
        else
        {
            // 数据可能被删除
            statusCode = StatusCode.ErrorDeleted.ToString();
        }
        return(returnValue);
    }
コード例 #5
0
        /// <summary>
        /// 将登录信息保存到XML文件中。
        /// 若不保存用户名密码,那就应该删除掉。
        /// </summary>
        /// <param name="userInfo">登录用户</param>
        private void SaveLogOnInfo(UserInfo userInfo)
        {
            SystemInfo.RememberPassword = this.chkRememberPassword.Checked;
            if (this.chkRememberPassword.Checked)
            {
                SystemInfo.CurrentUserName = userInfo.UserName;
                // SystemInfo.CurrentUserName = SecretHelper.AESEncrypt(userInfo.UserName);
                SystemInfo.CurrentPassword = SystemInfo.EncryptClientPassword ? SecretHelper.AESEncrypt(this.txtPassword.Text) : this.txtPassword.Text;
            }
            else
            {
                SystemInfo.CurrentUserName = string.Empty;
                SystemInfo.CurrentPassword = string.Empty;
            }

            //SystemInfo.AutoLogOn = this.chbAutoLogOn.Checked;

            // 保存用户的信息

            UserConfigHelper.SaveConfig();

            /*
             * // 写入注册表,有时候会没有权限,发生异常信息等,可以考虑写入XML文件
             * RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(@"Software\" + SystemInfo.CompanyName + "\\" + SystemInfo.SoftName);
             * if (this.chkRememberPassword.Checked)
             * {
             *  // 默认的信息写入注册表,呵呵需要改进一下
             *  registryKey.SetValue(SystemInfo.CurrentUserName, SecretUtil.Encrypt(userInfo.UserName));
             *  registryKey.SetValue(SystemInfo.CurrentPassword, SecretUtil.Encrypt(this.txtPassword.Text));
             * }
             * else
             * {
             *  registryKey.SetValue(SystemInfo.CurrentUserName, string.Empty);
             *  registryKey.SetValue(SystemInfo.CurrentPassword, string.Empty);
             * }
             */
        }
コード例 #6
0
 /// <summary>
 /// 用户密码加密处理功能
 /// 2014-06-20 XuWangBin V2.8 增加对修改密码最小长度、字母数字组合等强度检查。
 /// 2014-03-28 XuWangBin 修改用户登录表没有用户记录时设置密码自动增加一条数据。
 /// 用户的密码到底如何加密,数据库中如何存储用户的密码?
 /// 若是明文方式存储,在管理上会有很多漏洞,虽然调试时不方便,当时加密的密码相对是安全的,
 /// 而且最好是密码是不可逆的,这样安全性更高一些,各种不同的系统,这里适当的处理一下就饿可以了。
 /// </summary>
 /// <param name="password">用户密码</param>
 /// <returns>处理后的密码</returns>
 public virtual string EncryptUserPassword(string password)
 {
     return(SecretHelper.AESEncrypt(password));
 }
コード例 #7
0
        private void SaveConfigInfo()
        {
            //**********************************************************
            //一、客户端配置
            //**********************************************************
            SystemInfo.EncryptClientPassword = EncryptClientPassword.Checked;
            SystemInfo.AutoLogOn             = AutoLogOn.Checked;
            SystemInfo.RememberPassword      = RememberPassword.Checked;
            SystemInfo.LoadAllUser           = LoadAllUser.Checked;
            SystemInfo.EncryptDbConnection   = EncryptDbConnection.Checked;
            SystemInfo.ServiceUserName       = ServiceUserName.Text.Trim();
            SystemInfo.ServicePassword       = ServicePassword.Text.Trim();

            switch (RDIFrameworkDbType.Text.Trim())
            {
            case "SqlServer":
                SystemInfo.RDIFrameworkDbType = CurrentDbType.SqlServer;
                break;

            case "Oracle":
                SystemInfo.RDIFrameworkDbType = CurrentDbType.Oracle;
                break;

            case "MySql":
                SystemInfo.RDIFrameworkDbType = CurrentDbType.MySql;
                break;

            case "DB2":
                SystemInfo.RDIFrameworkDbType = CurrentDbType.DB2;
                break;

            case "Access":
                SystemInfo.RDIFrameworkDbType = CurrentDbType.Access;
                break;

            case "SQLite":
                SystemInfo.RDIFrameworkDbType = CurrentDbType.SQLite;
                break;

            default:
                SystemInfo.RDIFrameworkDbType = CurrentDbType.SqlServer;
                break;
            }
            SystemInfo.CurrentLanguage = CurrentLanguage.SelectedItem == null ? "zh-CN" : CurrentLanguage.SelectedItem.ToString();

            SystemInfo.RDIFrameworkDbConectionString = RDIFrameworkDbConection.Text.Trim();

            if (SystemInfo.EncryptDbConnection)
            {
                SystemInfo.RDIFrameworkDbConectionString = SecretHelper.AESEncrypt(SystemInfo.RDIFrameworkDbConectionString);
                SystemInfo.BusinessDbConnectionString    = SecretHelper.AESEncrypt(SystemInfo.BusinessDbConnectionString);
                SystemInfo.WorkFlowDbConnectionString    = SecretHelper.AESEncrypt(SystemInfo.WorkFlowDbConnectionString);
            }
            //**********************************************************
            //二、服务端配置
            //**********************************************************

            SystemInfo.AllowUserToRegister             = AllowUserToRegister.Checked;
            SystemInfo.EnableRecordLog                 = EnableRecordLog.Checked;
            SystemInfo.EnableCheckIPAddress            = EnableCheckIPAddress.Checked;
            SystemInfo.EnableUserAuthorization         = EnableUserAuthorization.Checked;
            SystemInfo.EnableModulePermission          = EnableModulePermission.Checked;
            SystemInfo.EnablePermissionItem            = EnablePermissionItem.Checked;
            SystemInfo.EnableTableFieldPermission      = EnableTableFieldPermission.Checked;
            SystemInfo.EnableTableConstraintPermission = EnableTableConstraintPermission.Checked;
            SystemInfo.EnableEncryptServerPassword     = EnableEncryptServerPassword.Checked;
            SystemInfo.EnableCheckPasswordStrength     = EnableCheckPasswordStrength.Checked;
            SystemInfo.NumericCharacters               = NumericCharacters.Checked;
            SystemInfo.CheckOnLine = CheckOnLine.Checked;
            SystemInfo.EnableOrganizePermission = EnableOrganizePermission.Checked;
            if (OnLineLimit.Text.Trim().Length > 0)
            {
                SystemInfo.OnLineLimit = OnLineLimit.Value;
            }

            if (OnLineTime0ut.Text.Trim().Length > 0)
            {
                SystemInfo.OnLineTime0ut = OnLineTime0ut.Value;
            }

            if (AccountMinimumLength.Text.Trim().Length > 0)
            {
                SystemInfo.AccountMinimumLength = AccountMinimumLength.Value;
            }

            if (PasswordChangeCycle.Text.Trim().Length > 0)
            {
                SystemInfo.PasswordChangeCycle = PasswordChangeCycle.Value;
            }

            if (PasswordErrorLockLimit.Text.Trim().Length > 0)
            {
                SystemInfo.PasswordErrorLockLimit = PasswordErrorLockLimit.Value;
            }

            if (PasswordErrorLockCycle.Text.Trim().Length > 0)
            {
                SystemInfo.PasswordErrorLockCycle = PasswordErrorLockCycle.Value;
            }

            SystemInfo.DefaultPassword = DefaultPassword.Text.Trim();

            if (PasswordMiniLength.Text.Trim().Length > 0)
            {
                SystemInfo.PasswordMiniLength = PasswordMiniLength.Value;
            }

            //**********************************************************
            //三、系统参数配置
            //**********************************************************
            SystemInfo.MainForm            = BusinessLogic.ConvertToString(MainForm.SelectedItem);
            SystemInfo.LogOnForm           = LogOnForm.Text.Trim();
            SystemInfo.LogOnAssembly       = LogOnAssembly.Text.Trim();
            SystemInfo.CustomerCompanyName = CustomerCompanyName.Text.Trim();
            //SystemInfo.ConfigurationFrom     = ConfigurationFrom.Text.Trim();
            SystemInfo.SoftName     = SoftName.Text.Trim();
            SystemInfo.SoftFullName = SoftFullName.Text.Trim();
            SystemInfo.Version      = Version.Text.Trim();
            SystemInfo.Service      = Service.Text.Trim();
            //SystemInfo.RegisterKey           = RegisterKey.Text;

            /**********************************************************
            * 四、错误报告反馈配置
            **********************************************************/
            SystemInfo.ErrorReportFrom         = ErrorReportFrom.Text.Trim();
            SystemInfo.ErrorReportMailServer   = ErrorReportMailServer.Text.Trim();
            SystemInfo.ErrorReportMailUserName = ErrorReportMailUserName.Text.Trim();
            SystemInfo.ErrorReportMailPassword = ErrorReportMailPassword.Text.Trim();


            UserConfigHelper.SaveConfig();
            //再次得到配置文件。这儿主要是对加密的数据在软件运行过程中是解密的。
            UserConfigHelper.GetConfig();
        }
コード例 #8
0
        private void SubmitForm(HttpContext context)
        {
            try
            {
                int      IsOk    = 1;
                var      key     = PublicMethod.GetString(getObj("key"));
                var      json    = PublicMethod.GetString(getObj("json"));
                UserInfo curUser = Utils.UserInfo;
                var      entity  = JsonHelper.JSONToObject <CiDbLinkDefineEntity>(json);
                if (string.IsNullOrEmpty(key))
                {
                    //增加
                    if (!string.IsNullOrEmpty(entity.LinkData))
                    {
                        entity.LinkData = SecretHelper.AESEncrypt(entity.LinkData);
                    }
                    entity.CreateBy     = curUser.RealName;
                    entity.CreateUserId = curUser.Id;
                    string statusCode, statusMessage;
                    RDIFrameworkService.Instance.DbLinkDefineService.Add(curUser, entity, out statusCode, out statusMessage);
                    context.Response.Write(statusCode == RDIFramework.Utilities.StatusCode.OKAdd.ToString()
                        ? new JsonMessage {
                        Success = true, Data = IsOk.ToString(), Message = statusMessage
                    }.ToString()
                        : new JsonMessage {
                        Success = false, Data = "0", Message = statusMessage
                    }.ToString());
                }
                else
                {
                    var updateEntity = RDIFrameworkService.Instance.DbLinkDefineService.GetEntity(curUser, key);
                    if (updateEntity != null)
                    {
                        updateEntity.LinkName = entity.LinkName;
                        updateEntity.LinkData = entity.LinkData;
                        if (!string.IsNullOrEmpty(entity.LinkData))
                        {
                            updateEntity.LinkData = SecretHelper.AESEncrypt(entity.LinkData);
                        }
                        else
                        {
                            updateEntity.LinkData = null;
                        }
                        updateEntity.LinkType    = entity.LinkType;
                        updateEntity.Description = entity.Description;
                        updateEntity.Enabled     = entity.Enabled;
                    }

                    if (curUser != null)
                    {
                        updateEntity.ModifiedBy     = curUser.RealName;
                        updateEntity.ModifiedUserId = curUser.Id;
                    }
                    string statusCode;
                    string statusMessage;
                    RDIFrameworkService.Instance.DbLinkDefineService.Update(curUser, updateEntity, out statusCode, out statusMessage);
                    context.Response.Write(statusCode == RDIFramework.Utilities.StatusCode.OKUpdate.ToString()
                        ? new JsonMessage {
                        Success = true, Data = IsOk.ToString(), Message = statusMessage
                    }.ToString()
                        : new JsonMessage {
                        Success = false, Data = "0", Message = statusMessage
                    }.ToString());
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(new JsonMessage {
                    Success = false, Data = "0", Message = "操作失败:" + ex.Message
                }.ToString());
            }
        }