コード例 #1
0
        public OperationResult ChangePassword(Models.ServiceModels.User user, string password)
        {
            OperationResult res = new OperationResult();

            if (string.IsNullOrEmpty(password))
            {
                res.AddResultCode(OperationErrors.PassErr);
            }
            if (user == null)
            {
                res.AddResultCode(OperationErrors.NullErr);
            }
            else
            {
                if (!IsExistsById(user.Id))
                {
                    res.AddResultCode(OperationErrors.UserNotExistErr);
                }
            }
            if (res.Success)
            {
                string salt                  = CryptoFunctions.GenerationSalt(32);
                string passwordHash          = CryptoFunctions.GetMd5Hash(password, salt);
                Models.EFModels.User newUser = Mapper.Map <Models.EFModels.User>(user);
                newUser.Password = passwordHash;
                newUser.Salt     = salt;
                _userRepository.ChangePassword(newUser);
            }
            return(res);
        }
コード例 #2
0
        public OperationResult CreateUser(Models.ServiceModels.User user, string password)
        {
            OperationResult res = new OperationResult();

            if (string.IsNullOrEmpty(password))
            {
                res.AddResultCode(OperationErrors.PassErr);
            }
            if (user == null)
            {
                res.AddResultCode(OperationErrors.NullErr);
            }
            else
            {
                if (string.IsNullOrEmpty(user.Login))
                {
                    res.AddResultCode(OperationErrors.LoginErr);
                }
                if (string.IsNullOrEmpty(user.FullName))
                {
                    res.AddResultCode(OperationErrors.FullNameErr);
                }
                if (string.IsNullOrEmpty(user.Roles.First().RoleName))
                {
                    res.AddResultCode(OperationErrors.RoleErr);
                }
                if (IsExists(user))
                {
                    res.AddResultCode(OperationErrors.UserExistErr);
                }
            }
            if (res.Success)
            {
                string salt         = CryptoFunctions.GenerationSalt(32);
                string passwordHash = CryptoFunctions.GetMd5Hash(password, salt);

                Models.EFModels.User newUser = Mapper.Map <Models.ServiceModels.User, Models.EFModels.User>(user);
                newUser.Password = passwordHash;
                newUser.Salt     = salt;
                _userRepository.Create(newUser);
            }
            return(res);
        }