Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Console_App_2
- {
- class Program
- {
- static void Main()
- {
- var users = new List<User>
- {
- new User // Riley
- {
- Username = "rileyhempel",
- Password = "test",
- QandA = new QandA()
- {
- Question = "What Premier League soccer team do you go for?",
- Answer = "Chelsea"
- }
- },
- new User // Steph
- {
- Username = "stephgolland",
- Password = "test2",
- QandA = new QandA()
- {
- Question = "What is your favourite animal?",
- Answer = "Horse"
- }
- },
- new User // Jordan
- {
- Username = "jordanberlyn",
- Password = "test3",
- QandA = new QandA()
- {
- Question = "What state / city do you live in?",
- Answer = "Queensland Brisbane"
- }
- },
- };
- // Introduction
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine("Hello!");
- Console.WriteLine("Welcome to the security test.");
- Console.WriteLine("To begin, please enter your Username and Password.");
- // Username
- Console.ForegroundColor = ConsoleColor.DarkCyan;
- Console.WriteLine("Username:");
- Console.ForegroundColor = ConsoleColor.Gray;
- var username = Console.ReadLine();
- var user = users.Find(i => i.Username == username);
- if (user == null)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Woops! Wrong Username. Try again.");
- Main();
- }
- // Password
- Console.ForegroundColor = ConsoleColor.DarkCyan;
- Console.WriteLine("Password:");
- Console.ForegroundColor = ConsoleColor.Black;
- var password = Console.ReadLine();
- if (password != user.Password)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Woops! Wrong Password. Try again.");
- Main();
- }
- // Security Question Introduction
- Console.Clear();
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine($"Welcome {user.Username}.");
- Console.WriteLine("Before we allow full access to your account, please take the time to answer the security question.");
- Console.WriteLine("Press 'enter' to continue.");
- Console.ReadLine();
- Console.Clear();
- // Security Question
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Security Question:");
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine($"{user.QandA.Question}");
- Console.ResetColor();
- var answer = Console.ReadLine();
- if (answer != user.QandA.Answer)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("Incorrect answer. Press Enter to log out and try again.");
- Console.ResetColor();
- Console.ReadLine();
- Console.Clear();
- Main();
- }
- // Login
- Console.Clear();
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("You have successfully logged in!");
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine("What would you like to do?");
- }
- public class User
- {
- public string Username;
- public string Password;
- public QandA QandA;
- }
- public class QandA // Question and Answer
- {
- public string Question; //
- public string Answer; //
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement