Exemplo n.º 1
0
        private void BtGeneratePasswords_Click(object sender, RoutedEventArgs e)
        {
            var contentBuilder = new StringBuilder();

            if (CbPasswordConsonants.IsChecked == true)
            {
                switch (CoBPasswordLetters.SelectedIndex)
                {
                case 0:
                    contentBuilder.Append("qQwWrRtTzZpPsSdDfFgGhHjJkKlLyYxXcCvVbBnNmM");
                    break;

                case 1:
                    contentBuilder.Append("QWRTZPSDFGHJKLYXCVBNM");
                    break;

                case 2:
                    contentBuilder.Append("qwrtzpsdfghjklyxcvbnm");
                    break;
                }
            }

            if (CbPasswordVocals.IsChecked == true)
            {
                switch (CoBPasswordLetters.SelectedIndex)
                {
                case 0:
                    contentBuilder.Append("aAeEiIoOuU");
                    break;

                case 1:
                    contentBuilder.Append("AEIOU");
                    break;

                case 2:
                    contentBuilder.Append("aeiou");
                    break;
                }
            }

            if (CbPasswordNumbers.IsChecked == true)
            {
                contentBuilder.Append("0123456789");
            }
            if (CbPasswordSymbols.IsChecked == true)
            {
                contentBuilder.Append(@"!§$@%&/()=?\}][{<>|,;.:-_#+*~^");
            }

            var passwordList = new List <string>(0);

            if (!NudPasswordLength.Value.HasValue)
            {
                return;
            }
            var length = NudPasswordLength.Value;

            if (contentBuilder.Length < 1)
            {
                return;
            }
            var content = contentBuilder.ToString();

            using (var random = new RNGCryptoServiceProvider())
            {
                for (var pw = 0; pw < NudPasswordCount.Value; ++pw)
                {
                    var password = new StringBuilder();
                    var pwLength = length;
                    while (0 < pwLength--)
                    {
                        password.Append(content[random.GetNextInt32(content.Length)]);
                    }
                    passwordList.Add(password.ToString());
                }
            }

            foreach (var password in passwordList)
            {
                LbPasswords.Items.Add(password);
            }
        }
Exemplo n.º 2
0
        public void GetNextInt32ThrowsException()
        {
            RNGCryptoServiceProvider rnd = null;

            Assert.That(() => rnd.GetNextInt32(), Throws.ArgumentNullException);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Shuffles the characters in a string.
 /// </summary>
 /// <param name="input">String to shuffle.</param>
 /// <returns>String with same characters but in a different order.</returns>
 public static string Shuffle(this string input)
 {
     using (var rnd = new RNGCryptoServiceProvider())
     {
         return(string.IsNullOrEmpty(input) ? string.Empty : new string(input.ToCharArray().OrderBy(x => rnd.GetNextInt32()).ToArray()));
     }
 }
Exemplo n.º 4
0
        public static IEnumerable <T> Shuffle <T>(this IEnumerable <T> array)
        {
            RNGCryptoServiceProvider rnd = new RNGCryptoServiceProvider();

            return(array.OrderBy(x => rnd.GetNextInt32()));
        }