Ejemplo n.º 1
0
        public async Task <int> AddUser(User user)
        {
            _ILogger.LogError("test");
            List <User> users = new List <User>(100000);

            for (int i = 0; i < 100000; i++)
            {
                var flag = false;
                if (i > 20)
                {
                    flag = true;
                }
                User user1 = new User
                {
                    UserID     = SequentialGuidGenerator.Instance.Create().ToString(),
                    ClassId    = 12,
                    CreateTime = DateTime.Now,
                    Money      = 23.32M,
                    PassWord   = MD5Encrypt.MD5Encrypt32(user.UserName + i),
                    Type       = UserEnum.user,
                    UserName   = $"test{i}",
                    IsUsed     = flag
                };
                users.Add(user1);
            }
            await _unitOfWork.BulkInsert(users);

            _unitOfWork.Commit();
            return(1);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="entity">用户信息</param>
        /// <returns></returns>
        public int InsertUser(Users entity)
        {
            //check
            if (string.IsNullOrWhiteSpace(entity.UserID))
            {
                throw new BusinessException("必须输入用户ID!");
            }
            if (string.IsNullOrWhiteSpace(entity.UserName))
            {
                throw new BusinessException("必须输入用户名!");
            }
            if (string.IsNullOrWhiteSpace(entity.Password))
            {
                throw new BusinessException("必须输入密码!");
            }

            var userList = UsersMgtDA.GetValidUserListByUserID(entity.UserID);

            if (userList != null && userList.Count > 0)
            {
                throw new BusinessException("用户ID已经存在!");
            }
            entity.UserAuthCode = GuidCode.GetGuid("D");
            entity.Password     = MD5Encrypt.MD5Encrypt32(string.Format("{0}-{1}", entity.Password, entity.UserAuthCode)).ToLower();
            return(UsersMgtDA.InsertUser(entity));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 用户登录方法
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="pass"></param>
        /// <returns></returns>
        public UserLoginResponse UserInfoLgoin(UserLoginRequest request)
        {
            UserLoginResponse response = new UserLoginResponse();

            if (string.IsNullOrEmpty(request.UserPhone))
            {
                response.Status  = false;
                response.Message = "手机号不能为空";
                return(response);
            }
            if (string.IsNullOrEmpty(request.UserPass))
            {
                response.Status  = false;
                response.Message = "密码不能为空";
                return(response);
            }
            var salt     = dal.GetUserInfoSalt(request.UserPhone);
            var password = MD5Encrypt.MD5Encrypt32(request.UserPass + salt);
            var res      = dal.UserInfoLgoin(request.UserPhone, password);

            if (!string.IsNullOrEmpty(res.UserPhone))
            {
                response.IsLoginSuccess = true;
                response.UName          = res.UserName;
                response.UserPhone      = res.UserPhone;
                response.UserId         = res.UserId;
                response.Message        = "登录成功";
            }
            else
            {
                response.IsLoginSuccess = false;
                response.Message        = "登录失败";
            }
            return(response);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public UserFindResponse FindPwd(UserFindRequest request)
        {
            UserFindResponse userFindResponse = new UserFindResponse();

            if (string.IsNullOrEmpty(request.Pwd))
            {
                userFindResponse.Status  = false;
                userFindResponse.Message = "密码不能为空";
                return(userFindResponse);
            }
            var password = MD5Encrypt.MD5Encrypt32(request.Pwd);
            var res      = dal.FindPwd(request.UserName, password);

            if (res > 0)
            {
                userFindResponse.FindSuccess = true;
                userFindResponse.Message     = "密码修改成功";
            }
            else
            {
                userFindResponse.FindSuccess = false;
                userFindResponse.Message     = "密码修改失败";
            }
            return(userFindResponse);
        }
Ejemplo n.º 5
0
        //登陆
        private void btnOk_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtUserName.Text))
            {
                new FailureWindows("请输入用户名!").ShowDialog();
                return;
            }

            if (string.IsNullOrEmpty(txtUserPW.Password))
            {
                new FailureWindows("请输入密码!").ShowDialog();
                return;
            }
            string pwd = MD5Encrypt.MD5Encrypt32(txtUserPW.Password);
            //从配置文件读取接口
            string manager = new BLL.User().Login(txtUserName.Text, pwd);

            if (manager.Equals(SystemVar.Success))
            {
                MainWindow main = new MainWindow();
                main.Show();
                this.Close();
            }
            else
            {
                if (manager.Equals(SystemVar.Exception))
                {
                    new FailureWindows("登录异常!").ShowDialog();
                }
                else
                {
                    new FailureWindows("用户名或密码有误!").ShowDialog();
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="userID">用户ID</param>
        /// <param name="userPwd">用户密码,明文</param>
        /// <param name="validateCode">验证码</param>
        /// <returns>true-登录成功;false-登录失败</returns>
        public bool Login(string userID, string userPwd, string validateCode)
        {
            var user = UserAuthDA.GetUserByUserID(userID);

            if (user == null)
            {
                throw new BusinessException("用户名不存在!");
            }
            var currPassword = MD5Encrypt.MD5Encrypt32(string.Format("{0}-{1}", userPwd, user.UserAuthCode)).ToLower();

            if (!currPassword.Equals(user.Password.ToLower()))
            {
                throw new BusinessException("密码错误!");
            }

            #region 写登录Log
            Logs log = new Logs()
            {
                Classes      = 1001,
                Section      = 1002,
                Family       = 1005,
                RefenceSysNo = user.SysNo.Value,
                Contents     = "登录成功。",
                InUserSysNo  = 0,
                InUserName   = "******"
            };
            LogsMgtService.Instance.InsertLogs(log);
            #endregion

            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 用户登录
        /// </summary>
        public UserLoginResponse UserLogin(UserLoginRequest request)
        {
            UserLoginResponse response = new UserLoginResponse();

            //非空验证
            if (string.IsNullOrEmpty(request.User.UserName))
            {
                response.Status  = false;
                response.Message = "用户名为空";
                return(response);
            }
            if (string.IsNullOrEmpty(request.User.UserPassword))
            {
                response.Status  = false;
                response.Message = "密码为空";
                return(response);
            }



            //根据用户名获取用户的盐
            string salt = UserDal.Instance.GetSaltByUserName(request.User.UserName);

            //将密码和盐拼接进项MD5加密
            string password = MD5Encrypt.MD5Encrypt32(request.User.UserPassword + salt);

            //给request参数重新赋值加密后的密码
            request.User.UserPassword = password;

            //调用dal层方法 拿到返回id
            var user = UserDal.Instance.UserLogin(request.User);

            //如果id>0登陆成功
            if (user != null)
            {
                //修改用户最后登录时间
                int res = UserDal.Instance.SetUserLastLoginTime(user.UserName);
                if (res > 0)
                {
                    response.Message = "登陆成功!";
                    response.User    = user;
                }
                else
                {
                    response.Status  = false;
                    response.Message = "登录失败,密码错误";
                }
            }
            else
            {
                response.Status  = false;
                response.Message = "登录失败,密码错误";
            }
            //返回
            return(response);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 登录按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            //数据是否填写完整
            if (string.IsNullOrEmpty(txtUid.Text))
            {
                MessageBox.Show("账号不允许为空!", "系统提示", MessageBoxButtons.OK);
                txtUid.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txtPwd.Text))
            {
                MessageBox.Show("密码不允许为空!", "系统提示", MessageBoxButtons.OK);
                txtPwd.Focus();
                return;
            }
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            dictionary.Add("loginPwd", MD5Encrypt.MD5Encrypt32(txtPwd.Text));
            dictionary.Add("loginNumber", txtUid.Text);
            dictionary.Add("type", 2);
            DataTable i = BLL.VerificationLogin(dictionary);

            if (i.Rows.Count > 0)
            {
                //将登录成功的用户名登记到文本框中,方便下次输入
                string s    = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
                string path = s + "user.dll";
                if (File.Exists(path))                                                    //判断文件是否存在
                {
                    if (!this.txtUid.AutoCompleteCustomSource.Contains(this.txtUid.Text)) //判断记录是否存在
                    {
                        StreamWriter sw = new StreamWriter(path, true);                   //不覆盖以前存入的记录
                        sw.WriteLine(this.txtUid.Text.Trim());                            //存入记录
                        sw.Close();
                        if (!this.txtUid.AutoCompleteCustomSource.Contains(this.txtUid.Text))
                        {
                            this.txtUid.AutoCompleteCustomSource.Add(this.txtUid.Text);
                        }
                    }
                }
                //存储ID,姓名及权限
                userMessage um = new userMessage();
                um.userID    = i.Rows[0]["loginNumber"].ToString();
                um.userName  = i.Rows[0]["userName"].ToString();
                um.userLimit = Convert.ToInt32(i.Rows[0]["userRights"]);
                //进入主页面
                frmMainWindow mw = new frmMainWindow(um);
                mw.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("登录失败!");
                txtPwd.SelectAll();
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 用户注册方法
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public UserAddResponse UserRegist(UserAddRequest request)
        {
            UserAddResponse response = new UserAddResponse();

            if (string.IsNullOrEmpty(request.UserName))
            {
                response.Status  = false;
                response.Message = "手机号不能为空";
                return(response);
            }
            if (string.IsNullOrEmpty(request.Pwd))
            {
                response.Status  = false;
                response.Message = "密码不能为空";
                return(response);
            }

            //判断手机号是否已注册
            var isExist = userDal.IsExistPhone(request.UserName);

            if (isExist)
            {
                response.Status  = false;
                response.Message = "手机号已存在";
                return(response);
            }

            //对密码进行加密
            //1 生成一个盐  为什么要生成一个盐?
            var salt = Generate.GenerateSalt();
            //2 加密
            var password = MD5Encrypt.MD5Encrypt32(request.Pwd + salt);

            UserInfo user = new UserInfo()
            {
                UserName    = request.UserName,
                PhoneNumder = request.UserName,//13621807335
                NickName    = request.UserName.ToNickName(),
                UserPass    = password,
                Salt        = salt
            };

            var res = userDal.UserRegist(user);

            if (res > 0)
            {
                response.IsRegistSuccess = true;
            }
            else
            {
                response.Status  = false;
                response.Message = "注册失败";
            }
            return(response);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 用户注册方法
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public UserRegistReponse UserInfoRegist(UserRegistRequest request)
        {
            UserRegistReponse response = new UserRegistReponse();

            if (string.IsNullOrEmpty(request.UserPhone))
            {
                response.Status  = false;
                response.Message = "手机号不能为空";
                return(response);
            }
            if (string.IsNullOrEmpty(request.UserPass))
            {
                response.Status  = false;
                response.Message = "密码不能为空";
                return(response);
            }
            //判断手机号是否已注册
            var isExist = dal.IsExistPhone(request.UserPhone);

            if (isExist)
            {
                response.Status  = false;
                response.Message = "手机号已存在";
                return(response);
            }
            //对密码进行加密
            //1 生成一个盐
            var salt = Generate.GenerateSalt();
            //2 加密
            var      password = MD5Encrypt.MD5Encrypt32(request.UserPass + salt);
            UserInfo user     = new UserInfo()
            {
                UserSalt  = salt,
                UserPhone = request.UserPhone,//13621807335
                UserName  = request.UserName,
                UserPass  = password
            };
            var res = dal.UserRegist(user);

            if (res > 0)
            {
                response.IsRegistSuccess = true;
                response.Message         = "注册成功";
            }
            else
            {
                response.Status  = false;
                response.Message = "注册失败";
            }
            return(response);
        }
Ejemplo n.º 11
0
        public UserAddResponse UserRegist(UserAddRequest request)
        {
            UserAddResponse response = new UserAddResponse();

            if (string.IsNullOrEmpty(request.UserName))
            {
                response.Status  = false;
                response.Message = "用户名不能为空";
                return(response);
            }
            if (string.IsNullOrEmpty(request.Pwd))
            {
                response.Status  = false;
                response.Message = "密码不能为空";
                return(response);
            }
            //是否已经注册
            var isExist = dal.IsExistPhone(request.UserName);

            if (isExist)
            {
                response.Status  = false;
                response.Message = "用户名已经存在";
                return(response);
            }
            //对密码进行加密
            //1.先生成一个盐
            var salt = Generate.GenerateSalt();
            //2.加密
            var      password = MD5Encrypt.MD5Encrypt32(request.Pwd);
            UserInfo userInfo = new UserInfo()
            {
                UserName = request.UserName,
                Phone    = request.Phone,
                PassWord = password,
                Salt     = salt
            };
            var res = dal.UserRegist(userInfo);

            if (res > 0)
            {
                response.RegistSuccess = true;
                response.Message       = "注册成功";
            }
            else
            {
                response.RegistSuccess = false;
                response.Message       = "注册失败";
            }
            return(response);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 修改个人密码
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public UserUpdPwdResponse UpdateUserPassword(UserUpdPwdRequest request)
        {
            UserUpdPwdResponse response = new UserUpdPwdResponse();

            if (request.User.UserId <= 0)
            {
                response.Status  = false;
                response.Message = "网络错误,请重新登录 userid<=0";
                return(response);
            }
            if (string.IsNullOrEmpty(request.User.UserPassword))
            {
                response.Status  = false;
                response.Message = "请输入新密码";
                return(response);
            }

            //获取用户盐
            var salt = UserDal.Instance.GetSaltByUserName(request.User.UName);

            //加密用户密码
            var password = MD5Encrypt.MD5Encrypt32(request.User.UserPassword + salt);

            //判断新密码是否和旧密码一致
            var uid = UserDal.Instance.CheckPassword(request.User.UName, password);

            if (uid > 0)
            {
                response.Status  = false;
                response.Message = "不能使用最近使用过的密码,请重新输入";
                return(response);
            }

            //给对象赋值
            request.User.UserPassword = password;

            //调用dal层方法ResetUserPasswod
            int res = UserDal.Instance.UpdateUserPassword(request.User);

            if (res > 0)
            {
                response.Message = "修改成功,请重新登录";
            }
            else
            {
                response.Status  = false;
                response.Message = "修改失败,请检查网络";
            }
            return(response);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 重置密码
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public UserResetPwdResponse ResetUserPassword(UserResetPwdRequest request)
        {
            UserResetPwdResponse response = new UserResetPwdResponse();

            if (string.IsNullOrEmpty(request.UserName))
            {
                response.Status  = false;
                response.Message = "用户名为空";
                return(response);
            }
            if (string.IsNullOrEmpty(request.NewPassword))
            {
                response.Status  = false;
                response.Message = "新密码为空";
                return(response);
            }

            //解码用户名字符串
            var decryptusername = request.UserName.Decrypt();
            //将新密码加盐进行md5加密
            var salt = UserDal.Instance.GetSaltByUserName(decryptusername);
            var encryptionPassword = MD5Encrypt.MD5Encrypt32(request.NewPassword + salt);

            //判断新密码是否和旧密码一致
            var uid = UserDal.Instance.CheckPassword(decryptusername, encryptionPassword);

            if (uid > 0)
            {
                response.Status  = false;
                response.Message = "不能使用最近使用过的密码,请重新输入";
                return(response);
            }


            //调用dal层重置密码方法
            int res = UserDal.Instance.ResetUserPasswod(decryptusername, encryptionPassword);

            //如果res>0修改成功
            if (res > 0)
            {
                response.Message = "修改成功!";
            }
            else
            {
                response.Status  = false;
                response.Message = "修改失败,请检查网络";
            }

            return(response);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, EventArgs e)
        {
            //验证是否为空
            foreach (Control item in this.Controls)
            {
                if (item is TextBox)
                {
                    if (string.IsNullOrEmpty(item.Text))
                    {
                        MessageBox.Show("不允许为空!");
                        return;
                    }
                }
            }
            //判断新密码与重复新密码是否一致
            if (txtNewPwd.Text != txtRePwd.Text)
            {
                MessageBox.Show("密码不一致");
            }
            //判断旧密码是否正确,如果正确,将进行修改密码操作
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            dictionary.Add("loginNumber", txtUid.Text);
            dictionary.Add("loginPwd", MD5Encrypt.MD5Encrypt32(txtOldPwd.Text));
            dictionary.Add("type", 2);
            if ((WHBLL.BLL.VerificationLogin(dictionary).Rows.Count > 0))
            {
                dictionary = new Dictionary <string, object>();
                dictionary.Add("loginNumber", txtUid.Text);
                dictionary.Add("loginPwd", MD5Encrypt.MD5Encrypt32(txtNewPwd.Text));
                dictionary.Add("userName", null);
                dictionary.Add("userRights", null);
                dictionary.Add("type", 2);
                if (WHBLL.BLL.ExecuteUser(dictionary) > 0)
                {
                    MessageBox.Show("修改成功!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("修改失败,请稍后再试!");
                }
            }
            else
            {
                MessageBox.Show("密码错误!");
            }
        }
Ejemplo n.º 15
0
        public UserLoginResponse UserLogin(UserLoginRequest request)
        {
            UserLoginResponse userLoginResponse = new UserLoginResponse();

            if (string.IsNullOrEmpty(request.UserName))
            {
                userLoginResponse.Status  = false;
                userLoginResponse.Message = "用户名不能为空";
                return(userLoginResponse);
            }
            if (string.IsNullOrEmpty(request.PassWord))
            {
                userLoginResponse.Status  = false;
                userLoginResponse.Message = "密码不能为空";
                return(userLoginResponse);
            }
            var      password = MD5Encrypt.MD5Encrypt32(request.PassWord);
            UserInfo userInfo = new UserInfo()
            {
                UserName = request.UserName,
                PassWord = password
            };

            userInfo = dal.UserLogin(userInfo.UserName, userInfo.PassWord);
            if (userInfo.Uid > 0)
            {
                userLoginResponse.Uid          = userInfo.Uid;
                userLoginResponse.UserImg      = userInfo.UserImg;
                userLoginResponse.UserName     = userInfo.UserName;
                userLoginResponse.DepartmentId = userInfo.DepartmentId;
                userLoginResponse.LoginSuccess = true;
                userLoginResponse.Message      = "登录成功";
            }
            else
            {
                userLoginResponse.LoginSuccess = false;
                userLoginResponse.Message      = "登录失败";
            }
            return(userLoginResponse);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 更新用户密码
        /// </summary>
        /// <param name="entity">用户信息</param>
        /// <param name="oldPassword">旧密码</param>
        public void UpdateUserPasswordBySysNo(Users entity, string oldPassword)
        {
            //check
            if (string.IsNullOrWhiteSpace(oldPassword))
            {
                throw new BusinessException("必须输入旧密码!");
            }
            if (string.IsNullOrWhiteSpace(entity.Password))
            {
                throw new BusinessException("必须输入新密码!");
            }

            var    user            = UsersMgtDA.GetValidUserByUserID(entity.UserID);
            string currOldPassword = MD5Encrypt.MD5Encrypt32(string.Format("{0}-{1}", oldPassword, user.UserAuthCode)).ToLower();

            if (!currOldPassword.Equals(user.Password))
            {
                throw new BusinessException("旧密码错误!");
            }

            entity.Password = MD5Encrypt.MD5Encrypt32(string.Format("{0}-{1}", entity.Password, user.UserAuthCode)).ToLower();
            UsersMgtDA.UpdateUserPasswordByUserID(entity);
        }
Ejemplo n.º 17
0
        public int ExistUser(string username, string password)
        {
            int    value = 0;
            string pwd   = MD5Encrypt.MD5Encrypt32(password);
            //从配置文件读取接口
            string manager = new BLL.User().Login(username, pwd);

            if (manager.Equals(SystemVar.Success))
            {
                value = 1;
            }
            else
            {
                if (manager.Equals(SystemVar.Exception))
                {
                    value = -1;
                }
                else
                {
                    value = 0;
                }
            }
            return(value);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 用户添加
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public UserAddResponse UserAdd(UserAddRequest request)
        {
            UserAddResponse response = new UserAddResponse();

            //非空判断
            if (string.IsNullOrEmpty(request.User.UserName))
            {
                response.Status  = false;
                response.Message = "用户名为空";
                return(response);
            }
            if (string.IsNullOrEmpty(request.User.UserPassword))
            {
                response.Status  = false;
                response.Message = "密码为空";
                return(response);
            }
            if (string.IsNullOrEmpty(request.User.Email))
            {
                response.Status  = false;
                response.Message = "邮箱为空";
                return(response);
            }
            if (request.User.AddressId <= 0)
            {
                response.Status  = false;
                response.Message = "请选择地址";
                return(response);
            }
            if (request.User.RoleId <= 0)
            {
                response.Status  = false;
                response.Message = "请选择角色";
                return(response);
            }
            if (request.User.CreatorId <= 0)
            {
                response.Status  = false;
                response.Message = "系统繁忙,creatorid<=0";
                return(response);
            }
            //判断用户名是否已被注册
            int uid = UserDal.Instance.UserNameExist(request.User.UserName);

            if (uid > 0)
            {
                response.Status  = false;
                response.Message = "用户名已存在";
                return(response);
            }

            //开始获取盐
            var salt = Generate.GenerateSalt();
            //获取md5加密密码
            var pwd = MD5Encrypt.MD5Encrypt32(request.User.UserPassword + salt);

            request.User.UserPassword = pwd;
            request.User.Salt         = salt;
            var res = UserDal.Instance.UserAdd(request.User);

            if (res < 0)
            {
                response.Status  = false;
                response.Message = "添加失败";
            }
            else
            {
                response.Message = "添加成功";
            }
            return(response);
        }