Exemplo n.º 1
0
        /// <summary>
        /// 验证密码
        /// </summary>
        /// <param name="Password"></param>
        /// <returns></returns>
        private RegUserResult CheckPassword(string Password)
        {
            RegUserResult _RegUserResult = new RegUserResult();

            //验证密码是否为空
            if (string.IsNullOrEmpty(Password))
            {
                _RegUserResult.isSuccess  = true;
                _RegUserResult.errMessage = "用户登录密码为空";
                return(_RegUserResult);
            }
            //
            string _password = Password.Trim();

            byte[] outputb = Convert.FromBase64String(Password);
            _password = Encoding.UTF8.GetString(outputb);
            //验证密码长度
            if (_password.Length < 6)
            {
                _RegUserResult.isSuccess  = true;
                _RegUserResult.errMessage = "用户登录密码最小长度必须大于等于6位字符";
                return(_RegUserResult);
            }
            _RegUserResult.isSuccess = true;
            return(_RegUserResult);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 验证用户
        /// </summary>
        /// <param name="Data"></param>
        /// <param name="type">0:新建;1:编辑</param>
        /// <returns></returns>
        private RegUserResult CheckUserData(User Data)
        {
            RegUserResult _RegUserResult = new RegUserResult();

            try
            {
                //验证用户名
                _RegUserResult = CheckUserName(Data);
                if (!_RegUserResult.isSuccess)
                {
                    return(_RegUserResult);
                }
                //验证密码
                _RegUserResult = CheckPassword(Data.password);
                if (!_RegUserResult.isSuccess)
                {
                    return(_RegUserResult);
                }
            }
            catch (Exception ex)
            {
                LogFactory _LogFactory = new LogFactory(this.GetType());
                _LogFactory.CreateLog(LogType.Error, "验证用户", "CheckUserData", ex);
                _RegUserResult.isSuccess  = false;
                _RegUserResult.errMessage = "用户注册失败";
            }
            _RegUserResult.isSuccess = true;
            return(_RegUserResult);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 验证用户名
        /// </summary>
        /// <param name="Data"></param>
        /// <param name="type">0:新建;1:编辑</param>
        /// <returns></returns>
        private RegUserResult CheckUserName(User Data)
        {
            RegUserResult _RegUserResult = new RegUserResult();

            //判断是否为空
            string userName = Data.loginName.Trim();

            if (string.IsNullOrEmpty(userName))
            {
                _RegUserResult.isSuccess  = false;
                _RegUserResult.errMessage = "用户登录名称不能为空";
                return(_RegUserResult);
            }
            //验证用户名长度是否小于3位
            if (userName.Length < 3)
            {
                _RegUserResult.isSuccess  = false;
                _RegUserResult.errMessage = "用户登录名称最小长度必须大于3位字符";
                return(_RegUserResult);
            }
            //验证用户名是否存在
            if (LoginNameIsRepeat(Data.loginName, Data.userKey))
            {
                _RegUserResult.isSuccess  = false;
                _RegUserResult.errMessage = "用户登录名称已经存在";
                return(_RegUserResult);
            }
            _RegUserResult.isSuccess = true;
            return(_RegUserResult);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 修改登录密码
        /// </summary>
        /// <param name="Param"></param>
        /// <returns></returns>
        public UpdatePasswordResult UpdatePassword(UpdatePasswordParam Param)
        {
            UpdatePasswordResult _Result = new UpdatePasswordResult();

            try
            {
                string oldPassword = EncryptPassword(Param.Param1);
                string newPassword = EncryptPassword(Param.Param2);
                User   _User       = GetCurrentUser();
                //验证旧密码是否正确
                string      sql          = @"select count(id) from de2_user where id=@id and password=@password";
                MySqlClient _MySqlClient = new MySqlClient();
                int         count        = Convert.ToInt32(_MySqlClient.ExecuteScalar(sql, new MySqlParameter("id", _User.id), new MySqlParameter("password", oldPassword)));
                if (count == 0)
                {
                    _Result.isSuccess  = false;
                    _Result.errMessage = "原密码不正确";
                    return(_Result);
                }
                //验证新密码
                RegUserResult CheckResult = CheckPassword(Param.Param2);
                if (!CheckResult.isSuccess)
                {
                    _Result.isSuccess  = false;
                    _Result.errMessage = CheckResult.errMessage;
                    return(_Result);
                }
                //修改密码
                sql = @"update de2_user set password=@password  where id=@id  ";
                _MySqlClient.ExecuteNonQuery(sql, new MySqlParameter("id", _User.id), new MySqlParameter("@password", newPassword));
                _Result.isSuccess = true;
                return(_Result);
            }
            catch (Exception ex)
            {
                LogFactory _LogFactory = new LogFactory(this.GetType());
                _LogFactory.CreateLog(LogType.Error, "修改登录密码", "UpdatePassword", ex);
            }
            return(_Result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 用户注册
        /// </summary>
        /// <param name="Data"></param>
        /// <returns></returns>
        public RegUserResult RegUser(User Data)
        {
            RegUserResult _result = new RegUserResult();

            try
            {
                if (Data == null)
                {
                    _result.isSuccess  = false;
                    _result.errMessage = "用户注册失败";
                    return(_result);
                }
                //验证数据有效性
                _result = CheckUserData(Data);
                if (!_result.isSuccess)
                {
                    return(_result);
                }

                Data.userKey        = Guid.NewGuid();
                Data.regTime        = DateTime.Now;
                Data.lastModifyTime = DateTime.Now;
                //加密密码
                Data.password = EncryptPassword(Data.password);
                if (RegUserCommit(Data))
                {
                    _result.isSuccess = true;
                }

                return(_result);
            }
            catch (Exception ex)
            {
                LogFactory _LogFactory = new LogFactory(this.GetType());
                _LogFactory.CreateLog(LogType.Error, "用户注册", "RegUserID", ex);
                _result.isSuccess  = false;
                _result.errMessage = "用户注册失败";
            }
            return(_result);
        }