Пример #1
0
        private string SetPassword(int userId, string newPwd, string oldPwd)
        {
            return(ServiceInvoke(unitOfWork =>
            {
                var userEntity = unitOfWork.UserRepository.Get(v => v.Id == userId).FirstOrDefault();
                if (userEntity == null)
                {
                    return "用户未找到";
                }

                if (PwdSecurityHelper.CheckEqual(oldPwd, userEntity.Password))
                {
                    userEntity.Password = PwdSecurityHelper.ComputeHash(newPwd);
                    userEntity.UpdatedDate = DateTime.Now;
                }
                else
                {
                    return "原密码错";
                }

                unitOfWork.UserRepository.Update(userEntity);

                return null;
            }));


            //using (UnitOfWork)
            //{
            //    var userEntity = UnitOfWork.UserRepository.Get(v => v.Id == userId).FirstOrDefault();
            //    if (userEntity == null)
            //    {
            //        return "用户未找到";
            //    }

            //    if (PwdSecurityHelper.CheckEqual(oldPwd, userEntity.Password))
            //    {
            //        userEntity.Password = PwdSecurityHelper.ComputeHash(newPwd);
            //        userEntity.UpdatedDate = DateTime.Now;
            //    }
            //    else
            //    {
            //        return "原密码错";
            //    }

            //    UnitOfWork.UserRepository.Update(userEntity);
            //}

            //return null;
        }
Пример #2
0
        private UserEntity CheckUser(string userName, string password)
        {
            var userEntity = ServiceInvoke(unitOfWork => unitOfWork.UserRepository.Get(v =>
                                                                                       String.Compare(v.Name, userName,
                                                                                                      StringComparison.OrdinalIgnoreCase) == 0)
                                           .FirstOrDefault());


            if (userEntity == null)
            {
                return(null);
            }

            return(PwdSecurityHelper.CheckEqual(password, userEntity.Password) ? userEntity : null);
        }