Ejemplo n.º 1
0
        public void Configure(RandomPasswordSettings settings)
        {
            PasswordLength = settings.PasswordLength;

            var sb = new StringBuilder();

            if (settings.IncludeDigits)
            {
                sb.Append(Digits);
            }
            if (settings.IncludeLowerLetters)
            {
                sb.Append(LowerLetters);
            }
            if (settings.IncludeUpperLetters)
            {
                sb.Append(UpperLetters);
            }

            IEnumerable <char> chars = sb.ToString();

            if (settings.ExcludeSimilarCharacters)
            {
                if (settings.IncludeDigits && settings.IncludeLowerLetters)
                {
                    chars = chars.Except("0o1l");
                }
                if (settings.IncludeDigits && settings.IncludeUpperLetters)
                {
                    chars = chars.Except("0O1I");
                }
                if (settings.IncludeLowerLetters && settings.IncludeUpperLetters)
                {
                    chars = chars.Except("oOlI");
                }
            }

            Chars = new string(chars.ToArray());
        }
Ejemplo n.º 2
0
 public RandomPassword(RandomPasswordSettings settings)
 {
     _random = new Random();
     Configure(settings);
 }