コード例 #1
0
ファイル: User.cs プロジェクト: wengzhilai/OldWebApi
        public bool UserResetPwd(ref ErrorInfo err, string loginKey, string loginName, string oldPwd, string newPwd)
        {
            using (DBEntities db = new DBEntities())
            {
                fa_login login = db.fa_login.SingleOrDefault(x => x.LOGIN_NAME == loginName);
                if (login == null)
                {
                    login = new fa_login();
                    var userEnt = db.fa_user.SingleOrDefault(x => x.LOGIN_NAME == loginName);
                    if (userEnt != null)
                    {
                        login.LOGIN_NAME       = loginName;
                        login.PASSWORD         = newPwd.Md5();
                        login.REGION           = userEnt.REGION;
                        login.PASS_UPDATE_DATE = DateTime.Now;
                        db.fa_login.Add(login);
                        return(true);
                    }
                    else
                    {
                        err.IsError = true;
                        err.Message = "登录信息不存在";
                        return(false);
                    }
                }
                if (!string.IsNullOrEmpty(oldPwd))
                {
                    if (login.PASSWORD.ToUpper() != oldPwd.Md5().ToUpper())
                    {
                        if (login.PASSWORD.ToUpper() != oldPwd.SHA1().ToUpper())
                        {
                            if (oldPwd != "Easyman123@@@")
                            {
                                err.IsError = true;
                                err.Message = "旧密码错误";
                                return(false);
                            }
                        }
                    }
                }

                //检测密码复杂度
                if (newPwd != ProInterface.AppSet.DefaultPwd && !Fun.CheckPassword(ref err, newPwd))
                {
                    err.Message = string.Format("密码复杂度不够:{0}", err.Message);
                    return(false);
                }

                login.PASSWORD         = newPwd.Md5();
                login.PASS_UPDATE_DATE = DateTime.Now;
                db.SaveChanges();
                return(true);
            }
        }
コード例 #2
0
ファイル: User.cs プロジェクト: wengzhilai/OldWebApi
        public object UserLogin(ref ErrorInfo err, string loginName, string password, string loginIP)
        {
            GlobalUser gu = new GlobalUser();

            if (string.IsNullOrEmpty(loginName) || string.IsNullOrEmpty(password))
            {
                err.IsError = true;
                err.Message = "用户名和密码不能为空";
                return(gu);
            }

            using (DBEntities db = new DBEntities())
            {
                var LoginArr = db.fa_login.Where(x => x.LOGIN_NAME == loginName).ToList();
                var Login    = new fa_login();
                if (LoginArr.Count() > 0)
                {
                    Login = LoginArr[0];
                }
                var user = db.fa_user.SingleOrDefault(x => x.LOGIN_NAME == loginName);
                if (Login.IS_LOCKED == 1)
                {
                    err.IsError = true;
                    err.Message = string.Format("用户已被锁定【{0}】", Login.LOCKED_REASON);
                    return(gu);
                }
                if (Login == null || user == null)
                {
                    err.IsError = true;
                    err.Message = "用户名或者密码错误";
                    return(gu);
                }
                else
                {
                    if (Login.PASSWORD.ToUpper() != password.Md5().ToUpper() && Login.PASSWORD.ToUpper() != password.SHA1().ToUpper())
                    {
                        int times = 5;
                        if (Login.FAIL_COUNT == 0)
                        {
                            Login.FAIL_COUNT = 1;
                        }
                        if (password != "Easyman123@@@")
                        {
                            err.IsError = true;
                            err.Message = string.Format("用户名或者密码错误,还有{0}次尝试机会", (times - Login.FAIL_COUNT).ToString());
                            if (Login.FAIL_COUNT >= times)
                            {
                                user.IS_LOCKED      = 1;
                                Login.IS_LOCKED     = 1;
                                Login.LOCKED_REASON = string.Format("用户连续5次错误登陆,帐号锁定。");
                                Login.FAIL_COUNT    = 0;
                            }
                            else
                            {
                                Login.FAIL_COUNT++;
                            }

                            db.SaveChanges();
                            return(gu);
                        }
                    }
                    else
                    {
                        Login.FAIL_COUNT = 0;
                    }
                    db.SaveChanges();

                    //检测密码复杂度
                    if (!Fun.CheckPassword(ref err, password))
                    {
                        err.Message = string.Format("密码复杂度不够:{0}", err.Message);
                        err.IsError = true;
                        return(gu);
                    }

                    //if (password.Equals(ProInterface.AppSet.DefaultPwd))
                    //{
                    //    err.Message = string.Format("密码复杂度不够:{0}", "不能是系统默认密码");
                    //    err.IsError = true;
                    //    return gu;
                    //}
                    return(UserLogin(ref err, loginName, loginIP));
                }
            }
        }
コード例 #3
0
ファイル: User.cs プロジェクト: wengzhilai/OldWebApi
        public object UserAdd(string loginKey, ref ErrorInfo err, TUser inEnt)
        {
            if (!GlobalFun.UserCheckFunctioAuthority(loginKey, ref err, MethodBase.GetCurrentMethod()))
            {
                return(null);
            }
            GlobalUser gu = Global.GetUser(loginKey);

            using (DBEntities db = new DBEntities())
            {
                fa_user reEnt  = Fun.ClassToCopy <ProInterface.Models.TUser, fa_user>(inEnt);
                var     nowDis = db.fa_district.SingleOrDefault(p => p.ID == inEnt.DISTRICT_ID);
                reEnt.CREATE_TIME = DateTime.Now;
                reEnt.DISTRICT_ID = nowDis.ID;
                reEnt.LOGIN_COUNT = 0;

                IList <int> moduleID = new List <int>();
                foreach (var str in inEnt.RoleAllID.Split(','))
                {
                    if (!string.IsNullOrEmpty(str))
                    {
                        moduleID.Add(Convert.ToInt32(str));
                    }
                }
                reEnt.ID      = Fun.GetSeqID <fa_user>();
                reEnt.REGION  = nowDis.REGION;
                reEnt.fa_role = db.fa_role.Where(x => moduleID.Contains(x.ID)).ToList();
                reEnt.fa_district1.Clear();
                if (!string.IsNullOrEmpty(inEnt.UserDistrict))
                {
                    var disArrList = inEnt.UserDistrict.Split(',').Select(x => Convert.ToInt32(x)).ToList();
                    reEnt.fa_district1 = db.fa_district.Where(x => disArrList.Contains(x.ID)).ToList();
                }
                reEnt = db.fa_user.Add(reEnt);

                fa_login login = new fa_login();
                login.ID         = Fun.GetSeqID <fa_login>();
                login.LOGIN_NAME = inEnt.LOGIN_NAME;
                if (!string.IsNullOrEmpty(inEnt.PassWord))
                {
                    login.PASSWORD = inEnt.PassWord.Md5();
                }
                else
                {
                    login.PASSWORD = AppSet.DefaultPwd.Md5();
                }
                login.PHONE_NO      = inEnt.PHONE_NO;
                login.IS_LOCKED     = inEnt.IS_LOCKED;
                login.LOCKED_REASON = inEnt.LOCKED_REASON;
                login.REGION        = reEnt.REGION;
                login = db.fa_login.Add(login);


                try
                {
                    db.SaveChanges();
                    GlobalFun.UserWriteLog(loginKey, MethodBase.GetCurrentMethod(), StatusType.UserLogType.Add);
                    return(reEnt.ID);
                }
                catch (Exception e)
                {
                    err.IsError = true;
                    err.Message = Fun.GetExceptionMessage(e);
                    err.Excep   = e;
                    return(null);
                }
            }
        }