static void Main(string[] args) { // Variables Guest guest = new Guest(); int choice = default; // Displays choice = Displays.DisplayInitialMenuMethodForProgram(); if (choice == 1) { // Variables for brute force and running while true int bruteForce = 0; bool run = true; DateTime date = new DateTime(); while (run == true) { // Check the guest's credentials guest = PasswordLogin(); // Run a query with the information run = SQLWork.SQLPasswordMatch(guest); // Count login attempts bruteForce += 1; if (bruteForce >= 3) { // Write the bruteforce attempts to a file WriteToFile.WriteBruteForceAttemptsToFile(guest, date); // Display the brute force message BruteForceMessage(); } } } if (choice == 2) { AddInformation(); } }
public static void AddInformation() { // Variables string adminName = default; string empName = default; byte[] encryptedPassword = default; var admin = new Admin(); var adminList = new List <Admin>(); var emp = new Employee <DateTime>(); var employeeList = new List <Employee <DateTime> >(); var guest = new Guest(); var hashedPassword = String.Empty; var password = String.Empty; var sortedDictionary = new SortedDictionary <int, Tuple <string, char, string> >(); // Ask Admin's name adminName = AskAdminName(); // Checking how I would save a byte to SQL ? encryptedPassword = AskPassword(); // AES to SHA512 hashedPassword = SHA512Crypto.Hash(encryptedPassword); admin = AddAdministrator(adminName, hashedPassword); // Add admin to a list adminList.Add(admin); // Menu Menu(adminName); // Add employee and return to list employeeList = AddEmployeeToList(empName); // Loop through Employee LoopThroughEmployeeList(employeeList); // Add Employee list to a file WriteToFile.WriteEmployeeListToFile(employeeList); WriteToFile.WriteAdminToFile(admin, DateTime.Now); // Assign a sorted dictionary from emp list and adminlist sortedDictionary = AllPersonnel(employeeList, adminList); // Display the sorted dictionary on console Displays.DisplaySortedDictionary(sortedDictionary); // Write the sorted dictionary to a file WriteToFile.WriteSortedDictionaryToFile(sortedDictionary); // Write password to File WriteToFile.WriteToPasswordFile(admin, hashedPassword); // DB Insert SQLWork.SQLInsert(sortedDictionary); // Enum test Console.ReadKey(); Console.Clear(); Console.WriteLine("Emp enum"); Employee <DateTime> .EnumEmployees(employeeList); }
/// <summary> /// Method for adding a user /// </summary> /// <returns>A new admin object</returns> public static Admin AddAdministrator(string adminName, string hashedPassword) { // Initialize an admin object var admin = new Admin(); // Assign passed in string to admin name admin.Name = adminName; // Assigned passed in hash to admin's password property admin.Password = hashedPassword; // Color for error throws string color = default; try // Try catch for adding an administrator's properties { admin.Number = AdminNumber(); try { SQLWork.SqlInsertAdmin(admin); } catch (SqlException sqlE) { // Display custom message for taken PK if (sqlE.Number == 2627) { Console.Clear(); Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine("\nAdmin number is already taken: " + sqlE.Message + ". Please hit any key and try again. \n"); Console.ResetColor(); Console.ReadKey(); Console.Clear(); AddAdministrator(adminName, hashedPassword); } else { Console.WriteLine("Another error occured!"); } } } catch (FormatException e) { ClearConsole(); Console.WriteLine(e.ToString()); color = "RED"; ChangeConsoleColor(color); } catch { ClearConsole(); color = "BLUE"; ChangeConsoleColor(color); } ClearConsole(); admin.DisplayAdminInfo(admin.Name, admin.Number); return(admin); }