Advertisement
JovanPapi

[VP - lab1] Zadaca 5

Mar 24th, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.59 KB | None | 0 0
  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.  
  28.             Console.WriteLine("Now in one line type some guesses for the passwords: ");
  29.             char[] separate = { ' ' };
  30.             string line = Console.ReadLine();
  31.             string[] guesses = line.Split(separate);
  32.  
  33.             if (guesses.Contains(easyPassword))
  34.             {
  35.                 Console.WriteLine("\nCongratulations! You have guessed the easy password.\n");
  36.             }
  37.             else
  38.                 Console.WriteLine("\nU didnt guessed the easy password. . .\n");
  39.            
  40.             if (guesses.Contains(normalPassword))
  41.             {
  42.                 Console.WriteLine("\nCongratulations! You have guessed the normal password.\n");
  43.             }
  44.  
  45.             else
  46.                 Console.WriteLine("\nU didnt guessed the normal password. . .\n");
  47.  
  48.             if (guesses.Contains(hardPassword))
  49.             {
  50.                 Console.WriteLine("\nCongratulations! You have guessed the hard password.\n");
  51.             }
  52.  
  53.             else
  54.                 Console.WriteLine("\nU didnt guessed the hard password. . .\n");
  55.            
  56.  
  57.             Console.ReadKey();
  58.            
  59.         }  
  60.  
  61.         private static string generateRandomPassword(PasswordStrenght passwordStrenght)
  62.         {
  63.             String password = "";
  64.             int choice = (int)passwordStrenght;
  65.             switch (choice)
  66.             {
  67.                 case 1: password = generateEasyPassword(); break;
  68.                 case 2: password = generateNormalPassword(); break;
  69.                 case 3: password = generateHardPassword(); break;
  70.             }
  71.             return password;
  72.         }
  73.  
  74.         private static string generateEasyPassword()
  75.         {
  76.             String buildPassword = "";
  77.             Random random = new Random();
  78.             int randomSize = random.Next(1,6);
  79.             for(int i = 1; i<=randomSize; i++)
  80.             {
  81.                 buildPassword += Convert.ToChar(random.Next(97, 122));
  82.             }
  83.             return buildPassword.ToLower();
  84.         }
  85.  
  86.         private static string generateNormalPassword()
  87.         {
  88.             String buildPassword = "";
  89.             Random random = new Random();
  90.             int randomSize = random.Next(6,10);
  91.             for(int i = 1; i<=randomSize; i++)
  92.             {
  93.                 buildPassword += Convert.ToChar(normalSkip(random));
  94.             }
  95.             return buildPassword.ToUpper();
  96.         }
  97.  
  98.         private static string generateHardPassword()
  99.         {
  100.             Random random = new Random();
  101.             String buildPassword = "";
  102.             int randomSize = random.Next(10, 20);
  103.             for(int i = 0; i<randomSize; i++)
  104.             {
  105.                 buildPassword += Convert.ToChar(hardSkip(random));
  106.             }
  107.             return buildPassword;
  108.         }
  109.  
  110.         private static int hardSkip(Random random)
  111.         {
  112.             int check = 0;
  113.             while (true)
  114.             {
  115.                 check = random.Next(33, 122);
  116.                 if((check >= 33 && check <= 47)||(check >= 97 && check <=122)
  117.                     ||(check >= 65 && check <= 90))
  118.                 {
  119.                     break;
  120.                 }
  121.                 else
  122.                 {
  123.                     continue;
  124.                 }
  125.             }
  126.             return check;
  127.         }
  128.  
  129.         private static int normalSkip(Random random)
  130.         {
  131.             int check = 0;
  132.             while (true)
  133.             {
  134.                 check = random.Next(48, 90);
  135.                 if (check >= 58 && check <= 64)
  136.                 {
  137.                     continue;
  138.                 }
  139.                 else
  140.                 {
  141.                     break;
  142.                 }
  143.             }
  144.             return check;
  145.         }
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement