public string Get(PasswordRequestOptions options)
        {
            var adjectives = Resources.adjectives.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            var nouns      = Resources.nouns.Split(new[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            return($"{adjectives[_rand.Next(0, adjectives.Length - 1)]} {nouns[_rand.Next(0, nouns.Length - 1)]}");
        }
Exemple #2
0
        internal string PasswordGenerator(PasswordRequestOptions options)
        {
            var goodPassword = false;

            var password = string.Empty;

            while (!goodPassword)
            {
                password = _stringSource.Get(options);

                if (options.CaseType.GetType() == typeof(CaseTypeLettersAndNumbersMixedCasing) ||
                    options.CaseType.GetType() == typeof(CaseTypeLettersMixedCasing))
                {
                    password = GenerateMixedCase(password);
                }

                if (options.CaseType.GetType() == typeof(CaseTypeNumbers) ||
                    options.CaseType.GetType() == typeof(CaseTypeLettersAndNumbers) ||
                    options.CaseType.GetType() == typeof(CaseTypeLettersAndNumbersMixedCasing))
                {
                    password = GenerateNumbers(password);
                }

                if (options.SpecialCharacter)
                {
                    password = GenerateSpecialCharacter(password);
                }

                password     = FinalizePassword(password);
                goodPassword = IsGoodPassword(password, options);
            }


            return(password);
        }
Exemple #3
0
        internal static bool IsGoodPassword(string password, PasswordRequestOptions options)
        {
            var lengthCheck = password.Length >= options.MinimumLength;

            if (!lengthCheck)
            {
                return(false);
            }
            var passCheck = options.CaseType.Check(password);

            if (!passCheck)
            {
                return(false);
            }

            if (options.SpecialCharacter)
            {
                return(!password.All(char.IsLetterOrDigit));
            }
            return(true);
        }
Exemple #4
0
 public string Get(PasswordRequestOptions options)
 {
     return(new string(Enumerable.Repeat(_chars, options.MinimumLength)
                       .Select(s => s[_rand.Next(s.Length)]).ToArray()));
 }
Exemple #5
0
 public string GetPassword(PasswordRequestOptions options)
 {
     return(PasswordGenerator(options));
 }