Exemplo n.º 1
0
        public void LogInfo(LoggingTypeModel.LogCategory logCategory, string message)
        {
            if (!LoggingLevelEnabled.Decide(LoggingLevel).Info)
            {
                return;
            }

            _logger.WriteToErrorLog("INFO", logCategory, AllowedCharacters.Replace(message), DateTime.Now);
        }
        public void LogDebug(LoggingTypeModel.LogCategory logCategory, string message)
        {
            if (!LoggingLevelEnabled.Decide(LoggingLevel).Debug)
            {
                return;
            }

            _logger.Write("DEBUG", logCategory, AllowedCharacters.Replace(message), DateTime.Now);
        }
Exemplo n.º 3
0
        public void Sanitize(Value value)
        {
            value.FieldName = Name ?? string.Empty;
            string sanitizedValue = TrimField ? value.OriginalValue.Trim()
                                              : value.OriginalValue;

            //If it wasn't in the original file, handle it in advance
            if (value.Missing || sanitizedValue == string.Empty)
            {
                if (!AllowedBlank)
                {
                    value.ErrorMsg = ValueIfBlank;
                }
                return;
            }

            //Removes any disallowed characters and retains only allowed characters
            var chars = sanitizedValue.ToCharArray();

            if (AllowedCharacters.Any())
            {
                chars = chars.Where(c => AllowedCharacters.Any(a => a == c)).ToArray();
            }
            if (DisallowedCharacters.Any())
            {
                chars = chars.Where(c => !DisallowedCharacters.Any(d => d == c)).ToArray();
            }

            //validate the length
            if (chars.Length > MaxLength ||
                chars.Length < MinLength)
            {
                value.SanitizedValue = new string(chars);
                value.ErrorMsg       = ValueIfWrongLength;
                return;
            }

            //run regex
            sanitizedValue = new string(chars);
            if (RegEx != string.Empty && !Regex.IsMatch(sanitizedValue, RegEx))
            {
                value.ErrorMsg = "Value failed regex check on value.";
                return;
            }

            //run any custom checks
            value.SanitizedValue = RemoveDoubleSpaces(sanitizedValue); //remove any double spaces
            CustomChecks.ForEach(c => c.Execute(value));

            //If this there are a fixed number of options, check for them
            if ((AllowedValues?.Count() ?? 0) != 0 &&
                !AllowedValues.Any(v => v == value.SanitizedValue))
            {
                value.ErrorMsg = ValueIfNotInAllowedOptions;
            }
        }
Exemplo n.º 4
0
        protected override void ExecuteCrmWorkFlowActivity(CodeActivityContext context, LocalWorkflowContext localContext)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (localContext == null)
            {
                throw new ArgumentNullException(nameof(localContext));
            }

            const string numbers           = @"0123456789";
            const string upperCaseLetters  = @"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            const string lowerCaseLetters  = @"abcdefghijklmnopqrstuvwxyz";
            const string specialCharacters = @"!""#$%&'()*+,./:;<>?@[\]^_{|}~";

            int    length = Length.Get(context);
            bool   includeUpperCaseLetters  = IncludeUpperCaseLetters.Get(context);
            bool   includeLowerCaseLetters  = IncludeLowerCaseLetters.Get(context);
            bool   includeNumbers           = IncludeNumbers.Get(context);
            bool   includeSpecialCharacters = IncludeSpecialCharacters.Get(context);
            string allowedCharacters        = AllowedCharacters.Get(context);

            if (!string.IsNullOrEmpty(allowedCharacters))
            {
                allowedCharacters = allowedCharacters.Trim();
            }

            if (length < 1)
            {
                throw new InvalidPluginExecutionException("Length must be greater than 0");
            }

            if (!includeUpperCaseLetters && !includeLowerCaseLetters && !includeNumbers && !includeSpecialCharacters && string.IsNullOrEmpty(allowedCharacters))
            {
                throw new InvalidPluginExecutionException(
                          "Choose to include Upper Case Letters, Lower Case Letters, Numbers, Special Characters, or supply a list of Allowed Characters");
            }

            var allowedValues = SetAllowedValues(allowedCharacters, includeLowerCaseLetters, lowerCaseLetters,
                                                 includeUpperCaseLetters, upperCaseLetters, includeNumbers, numbers, includeSpecialCharacters, specialCharacters);

            var result = GenerateRandom(length, allowedValues);

            RandomString.Set(context, result.ToString());
        }
Exemplo n.º 5
0
        public static bool FilterName(ref string name, out string message, int minLen = 3, int maxLen = 20)
        {
            const string AllowedCharacters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+-=/!#$%^&()? .,\'\"";

            if (name == null)
            {
                message = $"The name cannot be empty";
                return(false);
            }

            for (int i = 0; i < name.Length; i++)
            {
                if (!AllowedCharacters.Contains(name[i]))
                {
                    message = $"The name contains the illegal character '{name[i]}'";
                    return(false);
                }
            }

            name = name.Trim();

            for (int i = 1; i < name.Length; i++)
            {
                if (name[i] == name[i - 1] && name[i] == ' ')
                {
                    name.Remove(i, 1);
                    i--;
                }
            }

            if (name.Length < minLen)
            {
                message = $"The name needs to be at least {minLen} characters long, yours is {name.Length}.";
                return(false);
            }
            if (name.Length > maxLen)
            {
                message = $"The name needs to be maximum {maxLen} characters long, yours is {name.Length}.";
                return(false);
            }

            message = "Valid name";
            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Overridden OnKeyPress method
        /// </summary>
        /// <param name="e"></param>
        protected override void OnKeyPress(KeyPressEventArgs e)
        {
            if (AllowPaste && RaiseCustomPasteEvent && _pasteDetected && OnPaste != null)
            {
                PasteEventArgs args = new PasteEventArgs();
                args.Text = Clipboard.GetText();

                OnPaste(this, args);

                SelectedText = args.Text;
                e.Handled    = true;
            }
            else if ((AllowCut && _cutDetected) || (AllowCopy && _copyDetected))
            {
                e.Handled = false;
            }
            else if (AcceptsReturn && e.KeyChar == '\r')
            {
                e.Handled = false;
            }
            else
            {
                if (!String.IsNullOrEmpty(AllowedCharacters))
                {
                    e.Handled = !AllowedCharacters.Contains(e.KeyChar.ToString());

                    if (e.Handled && e.KeyChar == '\b' && AllowBackSpace)
                    {
                        e.Handled = !e.Handled;
                    }
                }
                else
                {
                    base.OnKeyPress(e);
                }
            }

            if (_pasteDetected)
            {
                _pasteDetected = false;
            }
        }
Exemplo n.º 7
0
        /// <inheritdoc />
        public Task <IdentityResult> ValidateAsync(UserManager <TUser> manager, TUser user, string password)
        {
            var result = IdentityResult.Success;

            // if AllowedCharacters is not defined in appsettings.json then the validator always returns success
            if (string.IsNullOrEmpty(AllowedCharacters))
            {
                return(Task.FromResult(result));
            }
            var isValid = password.All(x => AllowedCharacters.Contains(x));

            if (!isValid || string.IsNullOrWhiteSpace(password))
            {
                result = IdentityResult.Failed(new IdentityError {
                    Code        = ErrorDescriber,
                    Description = MessageDescriber.PasswordContainsNotAllowedChars
                });
            }
            return(Task.FromResult(result));
        }