Ejemplo n.º 1
0
        private bool ConformsLevel(PasswordStrength strength, int length, int distinctCount, CharOptions charOptions)
        {
            StrengthLevelData levelStt = _settings.StrengthLevels.FirstOrDefault(lvl => lvl.Strength == strength);

            if (levelStt != null && levelStt.Conforms(length, distinctCount, charOptions))
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
 public string GenerateStrongPassword()
 {
     var safeDigits = "23456789";
       var safeLetters = "ABCDEFGHJKMNPQRSTUVWXYZ";
       var safeSpecChars = "?&#%$";
       var safeLettersAndDigits = safeDigits + safeLetters;
       var strongStt = _settings.StrengthLevels.FirstOrDefault(lvl => lvl.Strength == PasswordStrength.Strong);
       if (strongStt == null)
     strongStt = new StrengthLevelData() { Strength = PasswordStrength.Strong, MinLength = 10,
     Options = CharOptions.Digit | CharOptions.Letter | CharOptions.SpecialChar | CharOptions.MixedCase };
       string pwd = string.Empty;
       var rand = new Random();
       while (pwd.Length < strongStt.MinLength) {
     pwd += safeLetters[rand.Next(safeLetters.Length)];
     pwd += safeDigits[rand.Next(safeDigits.Length)];
       }
       //Add mixed case and special char if specified
       if (strongStt.Options.IsSet(CharOptions.MixedCase))
     pwd += char.ToLowerInvariant(safeLetters[rand.Next(safeLetters.Length)]);
       if (strongStt.Options.IsSet(CharOptions.SpecialChar))
     pwd += safeSpecChars[rand.Next(safeSpecChars.Length)];
       return pwd;
 }
Ejemplo n.º 3
0
        public string GenerateStrongPassword()
        {
            var safeDigits           = "23456789";
            var safeLetters          = "ABCDEFGHJKMNPQRSTUVWXYZ";
            var safeSpecChars        = "?&#%$";
            var safeLettersAndDigits = safeDigits + safeLetters;
            var strongStt            = _settings.StrengthLevels.FirstOrDefault(lvl => lvl.Strength == PasswordStrength.Strong);

            if (strongStt == null)
            {
                strongStt = new StrengthLevelData()
                {
                    Strength = PasswordStrength.Strong, MinLength = 10,
                    Options  = CharOptions.Digit | CharOptions.Letter | CharOptions.SpecialChar | CharOptions.MixedCase
                }
            }
            ;
            string pwd  = string.Empty;
            var    rand = new Random();

            while (pwd.Length < strongStt.MinLength)
            {
                pwd += safeLetters[rand.Next(safeLetters.Length)];
                pwd += safeDigits[rand.Next(safeDigits.Length)];
            }
            //Add mixed case and special char if specified
            if (strongStt.Options.IsSet(CharOptions.MixedCase))
            {
                pwd += char.ToLowerInvariant(safeLetters[rand.Next(safeLetters.Length)]);
            }
            if (strongStt.Options.IsSet(CharOptions.SpecialChar))
            {
                pwd += safeSpecChars[rand.Next(safeSpecChars.Length)];
            }
            return(pwd);
        }