Esempio n. 1
0
        private static bool IsValidPasswordByPosition(PasswordRule rule, string password)
        {
            var firstRequirementIsMet  = password[rule.FirstRequirement - 1] == rule.RequiredCharacter;
            var secondRequirementIsMet = password[rule.SecondRequirement - 1] == rule.RequiredCharacter;

            return(firstRequirementIsMet ^ secondRequirementIsMet);
        }
Esempio n. 2
0
        private static bool IsValidPasswordByCount(PasswordRule rule, string password)
        {
            var requiredCharCount = 0;

            foreach (var character in password)
            {
                if (character == rule.RequiredCharacter)
                {
                    requiredCharCount++;
                }

                if (requiredCharCount > rule.SecondRequirement)
                {
                    return(false);
                }
            }

            return(requiredCharCount >= rule.FirstRequirement);
        }