示例#1
0
        public void CreateUser(User user)
        {
            if (this.genericMgr.FindAll<long>("select count(*) from User as u where u.Code = ?", new object[] { user.Code })[0] > 0)
            {
                throw new BusinessException(Resources.ACC.User.Errors_Existing_User, user.Code);
            }
            else
            {
                if (CheckePassword(user.ConfirmPassword))
                {
                    user.Password = EncryptHelper.Md5(user.ConfirmPassword);
                    this.genericMgr.Create(user);

                    UserUpdatePasswordLog upLog = new UserUpdatePasswordLog
                    {
                        UserCode = user.Code,
                        UserName = user.Name,
                        UpdateTime = DateTime.Now,
                        NewPassword = EncryptHelper.Md5(user.Password),
                    };
                    this.genericMgr.Create(upLog);

                    this.genericMgr.UpdateWithNativeQuery("exec USP_Busi_ChangePassword ?,?",
                        new object[] { user.Id, user.ConfirmPassword },
                        new IType[] { NHibernateUtil.String, NHibernateUtil.String });
                }
            }
        }
示例#2
0
        public void ChangePassword(string userCode, string oldPassword, string newPassword)
        {
            //强制密码历史
            int historyPasswordCount = int.Parse(systemMgr.GetEntityPreferenceValue(Entity.SYS.EntityPreference.CodeEnum.HistoryPasswordCount));

            User user = this.GetUser(userCode);

            if (!string.IsNullOrWhiteSpace(oldPassword))
            {
                if (!EncryptHelper.Md5(oldPassword).Equals(user.Password, StringComparison.OrdinalIgnoreCase))
                {
                    throw new BusinessException("旧密码不对,不能修改密码.");
                }
            }

            var ifExists = this.genericMgr.FindAllWithNativeSql<int>(string.Format(" select count(*) from ACC_UserUpdatePasswordLog where UserCode=? and NewPassword=? and Id in(select top {0} Id from ACC_UserUpdatePasswordLog where UserCode=? order by Id desc) ", historyPasswordCount), new object[] { userCode, EncryptHelper.Md5(newPassword), userCode })[0];
            if (ifExists > 0)
            {
                throw new BusinessException(string.Format(" 不符合强制密码历史,{0}次历史密码不能一致。 ", historyPasswordCount));
            }

            if (CheckePassword(newPassword))
            {
                SecurityContextHolder.Set(user);
                user.PasswordExpired = false;
                user.AccountLocked = false;
                user.AccountExpired = false;
                user.IsActive = true;
                user.Password = EncryptHelper.Md5(newPassword);
                this.genericMgr.Update(user);

                this.genericMgr.UpdateWithNativeQuery("exec USP_Busi_ChangePassword ?,?",
                new object[] { user.Id, user.Password },
                new IType[] { NHibernateUtil.String, NHibernateUtil.String });

                UserUpdatePasswordLog upLog = new UserUpdatePasswordLog
                {
                    UserCode = user.Code,
                    UserName = user.Name,
                    UpdateTime = DateTime.Now,
                    OldPassword =string.IsNullOrWhiteSpace(oldPassword)?oldPassword:EncryptHelper.Md5(oldPassword),
                    NewPassword = EncryptHelper.Md5(newPassword),
                };
                this.genericMgr.Create(upLog);

                this.genericMgr.FindAllWithNativeSql("if exists (select 1 from ACC_UserLoginFailLog where UserCode=?)begin delete ACC_UserLoginFailLog where UserCode=? end", new object[] { user.Code, user.Code });
            }
        }