Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace PasswordGenerator
- {
- class Program
- {
- static void Main(string[] args)
- {
- int length;
- string type;
- bool misspelled = true;
- var rnd = new Random();
- string[] numbers = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
- string[] letters = { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
- string[] numbersLetters = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };
- while (misspelled == true)
- {
- misspelled = false;
- Console.Write("\n Password length (characters): ");
- length = Int16.Parse(Console.ReadLine());
- Console.Write(" Password type ('letter', 'number', or 'alphanumeric'): ");
- type = Console.ReadLine();
- Console.WriteLine(" ");
- for(int i = length; i > 0; i--)
- {
- switch (type)
- {
- case "number":
- Console.Write(numbers[rnd.Next(0, 9)]);
- break;
- case "letter":
- Console.Write(letters[rnd.Next(0, 25)]);
- break;
- case "alphanumeric":
- Console.Write(numbersLetters[rnd.Next(0, 34)]);
- break;
- default:
- if(misspelled == false)
- {
- Console.WriteLine($" '{type}' is not an option. (did you mis-spell it?)");
- misspelled = true;
- }
- break;
- }
- }
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment