Ejemplo n.º 1
0
        /// <summary>
        /// 更新通讯密码
        /// </summary>
        /// <param name="oldPassword">原密码</param>
        /// <param name="newPassword">新密码</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>影响行数</returns>
        public virtual int ChangeCommunicationPassword(string oldPassword, string newPassword, out string statusCode)
        {
            #if (DEBUG)
                int milliStart = Environment.TickCount;
            #endif

            int returnValue = 0;
            // 密码强度检查
            if (BaseSystemInfo.CheckPasswordStrength)
            {
                if (String.IsNullOrEmpty(newPassword))
                {
                    statusCode = StatusCode.PasswordCanNotBeNull.ToString();
                    return returnValue;
                }
            }
            // 加密密码
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                oldPassword = this.EncryptUserPassword(oldPassword);
                newPassword = this.EncryptUserPassword(newPassword);
            }
            // 判断输入原始密码是否正确
            BaseUserEntity userEntity = new BaseUserEntity();
            userEntity.GetSingle(this.GetDataTableById(UserInfo.Id));
            if (userEntity.CommunicationPassword == null)
            {
                userEntity.CommunicationPassword = string.Empty;
            }
            // 密码错误
            if (!userEntity.CommunicationPassword.Equals(oldPassword))
            {
                statusCode = StatusCode.OldPasswordError.ToString();
                return returnValue;
            }
            // 更改密码
            returnValue = this.SetProperty(UserInfo.Id, new KeyValuePair<string, object>(BaseUserEntity.FieldCommunicationPassword, newPassword));
            if (returnValue == 1)
            {
                statusCode = StatusCode.ChangePasswordOK.ToString();
            }
            else
            {
                // 数据可能被删除
                statusCode = StatusCode.ErrorDeleted.ToString();
            }

            // 写入调试信息
            #if (DEBUG)
                int milliEnd = Environment.TickCount;
                Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " " + " BaseUserManager.ChangePassword(" + userEntity.Id + ")");
            #endif

            return returnValue;
        }
        /// <summary>
        /// 更新密码
        /// </summary>
        /// <param name="oldPassword">原密码</param>
        /// <param name="newPassword">新密码</param>
        /// <param name="statusCode">返回状态码</param>
        /// <returns>影响行数</returns>
        public virtual int ChangePassword(string oldPassword, string newPassword, out string statusCode)
        {
            #if (DEBUG)
                int milliStart = Environment.TickCount;
            #endif

            int returnValue = 0;
            // 密码强度检查
            if (BaseSystemInfo.CheckPasswordStrength)
            {
                if (String.IsNullOrEmpty(newPassword))
                {
                    statusCode = StatusCode.PasswordCanNotBeNull.ToString();
                    return returnValue;
                }
            }
            // 加密密码
            if (BaseSystemInfo.ServerEncryptPassword)
            {
                oldPassword = this.EncryptUserPassword(oldPassword);
                newPassword = this.EncryptUserPassword(newPassword);
            }
            // 判断输入原始密码是否正确
            BaseUserEntity userEntity = new BaseUserEntity();
            userEntity.GetSingle(this.GetDataTableById(UserInfo.Id));
            if (userEntity.UserPassword == null)
            {
                userEntity.UserPassword = string.Empty;
            }
            // 密码错误
            if (!userEntity.UserPassword.Equals(oldPassword))
            {
                statusCode = StatusCode.OldPasswordError.ToString();
                return returnValue;
            }
            // 对比是否最近2次用过这个密码
            if (BaseSystemInfo.CheckPasswordStrength)
            {
                int i = 0;
                BaseParameterManager parameterManager = new BaseParameterManager(this.DbHelper, this.UserInfo);
                DataTable dataTable = parameterManager.GetDataTableParameterCode("User", this.UserInfo.Id, "Password");
                foreach (DataRow dataRow in dataTable.Rows)
                {
                    string parameter = dataRow[BaseParameterEntity.FieldParameterContent].ToString();
                    if (parameter.Equals(newPassword))
                    {
                        statusCode = StatusCode.PasswordCanNotBeRepeat.ToString();
                        return returnValue;
                    }
                    i++;
                    {
                        // 判断连续2个密码就是可以了
                        if (i > 2)
                        {
                            break;
                        }
                    }
                }
            }
            // 更改密码,同时修改密码的修改日期
            List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
            parameters.Add(new KeyValuePair<string, object>(BaseUserEntity.FieldUserPassword, newPassword));
            // 注意日期格式,ACCESS中要用字符
            parameters.Add(new KeyValuePair<string, object>(BaseUserEntity.FieldChangePasswordDate, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")));
            returnValue = this.SetProperty(new KeyValuePair<string, object>(BaseUserEntity.FieldId, UserInfo.Id), parameters);
            if (returnValue == 1)
            {
                statusCode = StatusCode.ChangePasswordOK.ToString();
                // 若是强类型密码检查,那就保存密码修改历史,防止最近2-3次的密码相同的功能实现。
                if (BaseSystemInfo.CheckPasswordStrength)
                {
                    BaseParameterManager parameterManager = new BaseParameterManager(this.DbHelper, this.UserInfo);
                    BaseParameterEntity parameterEntity = new BaseParameterEntity();
                    parameterEntity.CategoryId = "User";
                    parameterEntity.ParameterId = this.UserInfo.Id;
                    parameterEntity.ParameterCode = "Password";
                    parameterEntity.ParameterContent = newPassword;
                    parameterEntity.DeletionStateCode = 0;
                    parameterEntity.Enabled = true;
                    parameterEntity.Worked = true;
                    parameterManager.AddEntity(parameterEntity);
                }
            }
            else
            {
                // 数据可能被删除
                statusCode = StatusCode.ErrorDeleted.ToString();
            }

            // 写入调试信息
            #if (DEBUG)
                int milliEnd = Environment.TickCount;
                Trace.WriteLine(DateTime.Now.ToString(BaseSystemInfo.TimeFormat) + " Ticks: " + TimeSpan.FromMilliseconds(milliEnd - milliStart).ToString() + " " + " BaseUserManager.ChangePassword(" + userEntity.Id + ")");
            #endif

            return returnValue;
        }
Ejemplo n.º 3
0
 public virtual bool SignedPassword(string signedPassword)
 {
     bool returnValue = false;
     // 密码强度检查
     if (BaseSystemInfo.CheckPasswordStrength)
     {
         if (String.IsNullOrEmpty(signedPassword))
         {
             return returnValue;
         }
     }
     // 加密密码
     if (BaseSystemInfo.ServerEncryptPassword)
     {
         signedPassword = this.EncryptUserPassword(signedPassword);
     }
     // 判断输入原始密码是否正确
     BaseUserEntity userEntity = new BaseUserEntity();
     userEntity.GetSingle(this.GetDataTableById(UserInfo.Id));
     if (!(userEntity.CommunicationPassword == null && signedPassword.Length == 0))
     {
         if (userEntity.SignedPassword.Equals(signedPassword))
         {
             returnValue = true;
         }
     }
     return returnValue;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 扮演用户
 /// </summary>
 /// <param name="id">用户主键</param>
 /// <returns>用户类</returns>
 public BaseUserInfo Impersonation(string id, out string statusCode)
 {
     BaseUserInfo userInfo = null;
     // 获得登录信息
     DataTable dataTableLogOn = this.GetDataTableById(id);
     BaseUserEntity userEntity = new BaseUserEntity();
     userEntity.GetSingle(dataTableLogOn);
     // 只允许登录一次,需要检查是否自己重新登录了,或者自己扮演自己了
     if (!UserInfo.Id.Equals(id))
     {
         if (BaseSystemInfo.CheckOnLine)
         {
             if (userEntity.UserOnLine > 0)
             {
                 statusCode = StatusCode.ErrorOnLine.ToString();
                 return userInfo;
             }
         }
     }
     userInfo = this.ConvertToUserInfo(userEntity);
     if (userEntity.IsStaff.Equals("1"))
     {
         // 获得员工的信息
         BaseStaffEntity staffEntity = new BaseStaffEntity();
         BaseStaffManager staffManager = new BaseStaffManager(DbHelper, UserInfo);
         DataTable dataTableStaff = staffManager.GetDataTableById(id);
         staffEntity.GetSingle(dataTableStaff);
         userInfo = staffManager.ConvertToUserInfo(staffEntity, userInfo);
     }
     statusCode = StatusCode.OK.ToString();
     // 登录、重新登录、扮演时的在线状态进行更新
     this.ChangeOnLine(id);
     return userInfo;
 }