Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Lab15
- {
- enum PasswordStrength : byte
- {
- easy = 1,
- normal = 2,
- hard = 3
- }
- class Program
- {
- public static String GeneratePassword(PasswordStrength passwordStrength)
- {
- if ((int)passwordStrength == 1)
- {
- Random random = new Random();
- int length= random.Next(1, 6);
- char[] password = new char[length];
- char[] easy = "abcdefghijklmnopqrstuvwxyz".ToCharArray();
- for (int i = 0; i < length; i++)
- {
- password[i] = easy[random.Next(0, 25)];
- }
- Console.WriteLine("Generated Easy Password.");
- String pw = new string(password);
- return pw;
- }
- else if ((int)passwordStrength == 2)
- {
- Random random = new Random();
- int length = random.Next(6, 10);
- char[] password = new char[length];
- char[] normal = "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray();
- for (int i = 0; i < length; i++)
- {
- password[i] = normal[random.Next(0, 61)];
- }
- Console.WriteLine("Generated Normal Password.");
- String pw = new string(password);
- return pw;
- }
- else if ((int)passwordStrength == 3)
- {
- Random random = new Random();
- int length = random.Next(10, 20);
- char[] password = new char[length];
- char[] hard = "$%#@!*abcdefghijklmnopqrstuvwxyz1234567890?;:ABCDEFGHIJKLMNOPQRSTUVWXYZ^&".ToCharArray();
- for (int i = 0; i < length; i++)
- {
- password[i] = hard[random.Next(0, 72)];
- }
- Console.WriteLine("Generated Hard Password.");
- String pw = new string(password);
- return pw;
- }
- else
- {
- Console.WriteLine("You done messed up");
- String empty = null;
- return empty;
- }
- }
- static void Main(string[] args)
- {
- int n;
- Console.WriteLine("Enter Number for Password Strength for Random Generated Password: ");
- Console.WriteLine("1 = Easy; \n2 = Normal; \n3 = Hard.");
- n = Convert.ToInt16(Console.ReadLine());
- PasswordStrength N = (PasswordStrength)n;
- String generatedPassword = GeneratePassword(N);
- Console.WriteLine("Generated password = '{0}' ", generatedPassword);
- Console.WriteLine("Enter your guesses for what the password 'might' be.");
- String s = Console.ReadLine();
- String[] guesses = s.Split(' ');
- int counter = 0;
- for(int i = 0; i < guesses.Length; i++)
- {
- if (guesses[i].Equals(generatedPassword))
- {
- counter=1;
- }
- }
- if (counter == 1)
- Console.WriteLine("You have eyes.");
- else if(counter == 0)
- Console.WriteLine("You are blind");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement