Advertisement
777vasil

[VP] Password Strength

Mar 26th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.44 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Lab15
  4. {
  5.     enum PasswordStrength : byte
  6.     {
  7.         easy = 1,
  8.         normal = 2,
  9.         hard = 3
  10.     }
  11.     class Program
  12.     {
  13.         public static String GeneratePassword(PasswordStrength passwordStrength)
  14.         {
  15.             if ((int)passwordStrength == 1)
  16.             {
  17.                 Random random = new Random();
  18.  
  19.                 int length= random.Next(1, 6);
  20.                 char[] password = new char[length];
  21.  
  22.                 char[] easy = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
  23.  
  24.                 for (int i = 0; i < length; i++)
  25.                 {
  26.                     password[i] = easy[random.Next(0, 25)];
  27.                 }
  28.  
  29.                 Console.WriteLine("Generated Easy Password.");
  30.                 String pw = new string(password);
  31.                 return pw;
  32.             }
  33.  
  34.             else if ((int)passwordStrength == 2)
  35.             {
  36.                 Random random = new Random();
  37.  
  38.                 int length = random.Next(6, 10);
  39.                 char[] password = new char[length];
  40.  
  41.                 char[] normal = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
  42.  
  43.                 for (int i = 0; i < length; i++)
  44.                 {
  45.                     password[i] = normal[random.Next(0, 61)];
  46.                 }
  47.                 Console.WriteLine("Generated Normal Password.");
  48.                 String pw = new string(password);
  49.                 return pw;
  50.             }
  51.  
  52.             else if ((int)passwordStrength == 3)
  53.             {
  54.                 Random random = new Random();
  55.                
  56.                 int length = random.Next(10, 20);
  57.                 char[] password = new char[length];
  58.  
  59.                 char[] hard = "$%#@!*abcdefghijklmnopqrstuvwxyz1234567890?;:ABCDEFGHIJKLMNOPQRSTUVWXYZ^&".ToCharArray();
  60.  
  61.                 for (int i = 0; i < length; i++)
  62.                 {
  63.                     password[i] = hard[random.Next(0, 72)];
  64.                 }
  65.                 Console.WriteLine("Generated Hard Password.");
  66.                 String pw = new string(password);
  67.                 return pw;
  68.             }
  69.             else
  70.             {
  71.                 Console.WriteLine("You done messed up");
  72.                 String empty = null;
  73.                 return empty;
  74.             }
  75.         }
  76.        
  77.         static void Main(string[] args)
  78.         {
  79.             int n;
  80.             Console.WriteLine("Enter Number for Password Strength for Random Generated Password: ");
  81.             Console.WriteLine("1 = Easy; \n2 = Normal; \n3 = Hard.");
  82.             n = Convert.ToInt16(Console.ReadLine());
  83.             PasswordStrength N = (PasswordStrength)n;
  84.             String generatedPassword = GeneratePassword(N);
  85.  
  86.             Console.WriteLine("Generated password = '{0}' ", generatedPassword);
  87.  
  88.             Console.WriteLine("Enter your guesses for what the password 'might' be.");
  89.  
  90.             String s = Console.ReadLine();
  91.             String[] guesses = s.Split(' ');
  92.             int counter = 0;
  93.  
  94.             for(int i = 0; i < guesses.Length; i++)
  95.             {
  96.                 if (guesses[i].Equals(generatedPassword))
  97.                 {
  98.                     counter=1;
  99.                 }
  100.             }
  101.  
  102.             if (counter == 1)
  103.                 Console.WriteLine("You have eyes.");
  104.             else if(counter == 0)
  105.                 Console.WriteLine("You are blind");
  106.  
  107.             Console.ReadKey();
  108.         }
  109.     }
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement