SHARE
TWEET

Untitled

a guest Mar 24th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Lab15_VP
  8. {
  9.  
  10.     class Program
  11.     {
  12.        
  13.         private enum PasswordStrenght { easy=1,normal=2,hard=3 }
  14.        
  15.         static void Main(string[] args)
  16.         {
  17.  
  18.             String easyPassword = generateRandomPassword(PasswordStrenght.easy);
  19.             String normalPassword = generateRandomPassword(PasswordStrenght.normal);
  20.             String hardPassword = generateRandomPassword(PasswordStrenght.hard);
  21.  
  22.             if(easyPassword != "" && normalPassword != "" && hardPassword != "")
  23.             {
  24.                 Console.WriteLine("Easy, normal & hard password were generated successfully!");
  25.                 Console.WriteLine(easyPassword + "\n" + normalPassword + "\n" + hardPassword + "\n");
  26.             }
  27.             Console.WriteLine("Now in one line type some guesses for the passwords: ");
  28.             char[] separate = { ' ' };
  29.             string line = Console.ReadLine();
  30.             string[] guesses = line.Split(separate);
  31.             if (guesses.Contains(easyPassword))
  32.             {
  33.                 Console.WriteLine("\nCongratulations! You have guessed the easy password.\n");
  34.             }
  35.             else
  36.             {
  37.                 Console.WriteLine("\nU didnt guessed the easy password. . .\n");
  38.             }
  39.             if (guesses.Contains(normalPassword))
  40.             {
  41.                 Console.WriteLine("\nCongratulations! You have guessed the normal password.\n");
  42.             }
  43.             else
  44.             {
  45.                 Console.WriteLine("\nU didnt guessed the normal password. . .\n");
  46.             }
  47.             if (guesses.Contains(hardPassword))
  48.             {
  49.                 Console.WriteLine("\nCongratulations! You have guessed the hard password.\n");
  50.             }
  51.             else
  52.             {
  53.                 Console.WriteLine("\nU didnt guessed the hard password. . .\n");
  54.             }
  55.             Console.ReadKey();
  56.            
  57.         }  
  58.         private static string generateRandomPassword(PasswordStrenght passwordStrenght)
  59.         {
  60.             String password = "";
  61.             int choice = (int)passwordStrenght;
  62.             switch (choice)
  63.             {
  64.                 case 1: password = generateEasyPassword(); break;
  65.                 case 2: password = generateNormalPassword(); break;
  66.                 case 3: password = generateHardPassword(); break;
  67.             }
  68.             return password;
  69.         }
  70.         private static string generateEasyPassword()
  71.         {
  72.             String buildPassword = "";
  73.             Random random = new Random();
  74.             int randomSize = random.Next(1,6);
  75.             for(int i = 1; i<=randomSize; i++)
  76.             {
  77.                 buildPassword += Convert.ToChar(random.Next(97, 122));
  78.             }
  79.             return buildPassword.ToLower();
  80.         }
  81.         private static string generateNormalPassword()
  82.         {
  83.             String buildPassword = "";
  84.             Random random = new Random();
  85.             int randomSize = random.Next(6,10);
  86.             for(int i = 1; i<=randomSize; i++)
  87.             {
  88.                 buildPassword += Convert.ToChar(normalSkip(random));
  89.             }
  90.             return buildPassword.ToUpper();
  91.         }
  92.         private static string generateHardPassword()
  93.         {
  94.             Random random = new Random();
  95.             String buildPassword = "";
  96.             int randomSize = random.Next(10, 20);
  97.             for(int i = 0; i<randomSize; i++)
  98.             {
  99.                 buildPassword += Convert.ToChar(hardSkip(random));
  100.             }
  101.             return buildPassword;
  102.         }
  103.         private static int hardSkip(Random random)
  104.         {
  105.             int check = 0;
  106.             while (true)
  107.             {
  108.                 check = random.Next(33, 122);
  109.                 if((check >= 33 && check <= 47)||(check >= 97 && check <=122)||(check >= 65 && check <= 90))
  110.                 {
  111.                     break;
  112.                 }
  113.                 else
  114.                 {
  115.                     continue;
  116.                 }
  117.             }
  118.             return check;
  119.         }
  120.  
  121.         private static int normalSkip(Random random)
  122.         {
  123.             //Random random = new Random();
  124.             int check = 0;
  125.             while (true)
  126.             {
  127.                 check = random.Next(48, 90);
  128.                 if (check >= 58 && check <= 64)
  129.                 {
  130.                     continue;
  131.                 }
  132.                 else
  133.                 {
  134.                     break;
  135.                 }
  136.             }
  137.             return check;
  138.         }
  139.     }
  140. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top