Guest User

passwordGenerator

a guest
Jun 18th, 2021
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.20 KB | None | 0 0
  1. using System;
  2.  
  3. namespace PasswordGenerator
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int length;
  10.             string type;
  11.             bool misspelled = true;
  12.  
  13.             var rnd = new Random();
  14.  
  15.             string[] numbers = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
  16.             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" };
  17.             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" };
  18.            
  19.             while (misspelled == true)
  20.             {
  21.                 misspelled = false;
  22.                
  23.                 Console.Write("\n  Password length (characters): ");
  24.                 length = Int16.Parse(Console.ReadLine());
  25.  
  26.                 Console.Write("  Password type ('letter', 'number', or 'alphanumeric'): ");
  27.                 type = Console.ReadLine();
  28.  
  29.                 Console.WriteLine(" ");
  30.  
  31.                 for(int i = length;  i > 0; i--)
  32.                 {
  33.                     switch (type)
  34.                     {
  35.                         case "number":
  36.                             Console.Write(numbers[rnd.Next(0, 9)]);
  37.                             break;
  38.                         case "letter":
  39.                             Console.Write(letters[rnd.Next(0, 25)]);
  40.                             break;
  41.                         case "alphanumeric":
  42.                             Console.Write(numbersLetters[rnd.Next(0, 34)]);
  43.                             break;
  44.                         default:
  45.                             if(misspelled == false)
  46.                             {
  47.                                 Console.WriteLine($"  '{type}' is not an option. (did you mis-spell it?)");
  48.                                 misspelled = true;
  49.                                
  50.                             }
  51.                             break;
  52.                     }
  53.                 }
  54.             }
  55.            
  56.             Console.ReadKey();
  57.  
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment