public static void AdminInterface() { Console.Clear(); Console.WriteLine("-----------------------------------------------------------------\n"); Console.WriteLine("\t ADMIN CONTROLS SYSTEM\n"); Console.WriteLine("\t Please select one option"); Console.WriteLine("\t 1. See users and passwords"); Console.WriteLine("\t 2. Update admin password"); Console.WriteLine("\t 3. Delete user account"); Console.WriteLine("\t 4. Exit the system\n"); Console.Write("\t Enter Selection: "); string userInput = Console.ReadLine(); Console.WriteLine("\n-----------------------------------------------------------------"); if (userInput == "1") { Console.WriteLine("\nHere is a list of all the users"); for (int i = 0; i < userList.Count; i++) { Console.WriteLine($" [{userList[i]}, {u[userList[i]]}]"); } } if (userInput == "2") { //Only uses while running Console.Write("Enter new password: "******"Admin"] = Console.ReadLine(); } if (userInput == "3") { for (int i = 0; i < userList.Count; i++) { Console.WriteLine($" [{userList[i]}, {u[userList[i]]}]"); } Console.Write("\nWhich user do you want to remove?: "); string userName = Console.ReadLine(); u.DeleteUser(userName); userList.Remove(userName); using (var db = new GroupAssignmentContext()) { db.Users.RemoveRange(db.Users.Where(x => x.UserName == userName)); db.SaveChanges(); } } if (userInput == "4") { Console.WriteLine("Bye bye!"); return; } if (userInput != "1" && userInput != "2" && userInput != "3" && userInput != "4") { Console.WriteLine("\nOnly 1, 2, 3, and 4 are correct inputs. Please select one of those numbers.\n"); } Console.WriteLine("\nPress any key to continue."); Console.ReadKey(); AdminInterface(); }
public static void Main(String[] args) { string inputPassword; char[] encryptedFakeRealPassword = { (char)36, (char)61, (char)72, (char)72, (char)75, (char)13, (char)14, (char)15 }; string encryptedRealPassword = new string(encryptedFakeRealPassword); string encryptedInputPassword; string usernameInput; string message = ""; string filepath; int key = 65500; UserList users = new UserList(); ConsoleKeyInfo auswahl = new ConsoleKeyInfo(); bool passed = false; User currentUser = null; while (auswahl.Key != ConsoleKey.X) { Console.Clear(); if (message != "") { Console.Write(message + "\n"); message = ""; } if (passed && currentUser != null) { Console.WriteLine("Eingeloggt als: " + currentUser.Username); } Console.Write("Was wollen sie tun? \n"); if (!passed) { Console.Write("Login (L) \n"); Console.Write("Registrieren (R) \n"); } else { Console.Write("Ausloggen (L) \n"); Console.Write("Nutzer kopieren (C) \n"); } Console.Write("Nutzer auflisten (i) \n"); Console.Write("Nutzerliste Exportieren (E) \n"); Console.Write("Nutzerliste aus Datei Importieren (F) \n"); Console.Write("User löschen (D) \n"); Console.Write("Verlassen (X) \n"); auswahl = Console.ReadKey(); switch (auswahl.Key) { case ConsoleKey.F: filepath = GetFilePath(); UserList tempUsers = UserList.importFromFile(filepath); if (tempUsers != null) { HandleImportedUsers(tempUsers, users); } else { message = "Fehler beim importieren aus Datei bitte Dateipfad überprüfen!"; } break; case ConsoleKey.E: filepath = GetFilePath(); users.saveToFile(filepath); message = "Saved To File!"; break; case ConsoleKey.C: if (passed) { Console.Write("\n Nutzer zum kopieren auswählen \n"); Console.Write(users.GetUserList()); int index = GetNumber(); Console.Write("byte Array Length: " + users.FindByIndex(index).SerialisiereBinaer().Length + "\n"); User habib = User.DeserialisiereBinär(users.FindByIndex(index).SerialisiereBinaer()); users.AddUser(habib); message = "Nutzer: " + habib.Username + " erfolgreich kopiert!"; } break; case ConsoleKey.L: if (!passed) { while (!passed) { Console.Write("\nEinloggen!"); Console.Write("\nUsername: "******"Passwort: "); inputPassword = Console.ReadLine(); // Eingelesenes Passwort durch Aufruf der Funktion Encrypt verschlüsseln: encryptedInputPassword = Encrypt(inputPassword, key); // Überprüfen ob Login Daten übereinstimmen: Console.Write(users.GetUserList()); User existingUser = users.FindUser(new User(usernameInput, encryptedInputPassword)); if (existingUser != null) { currentUser = existingUser; passed = true; } if (passed) { inputPassword = null; } else { Console.Write("\nUsername oder Passwort Falsch! Wiederholen? Y/n \n"); auswahl = Console.ReadKey(); if (auswahl.Key == ConsoleKey.N) { break; } } } } else { currentUser = null; passed = false; } break; case ConsoleKey.R: if (!passed) { Console.Write("\nRegistrieren!"); Console.Write("\nUsername: "******"Passwort: "); inputPassword = Console.ReadLine(); // Eingelesenes Passwort durch Aufruf der Funktion Encrypt verschlüsseln: encryptedInputPassword = Encrypt(inputPassword, key); User newUser = new User(usernameInput, encryptedInputPassword); users.AddUser(newUser); currentUser = newUser; passed = true; } break; case ConsoleKey.D: if (passed) { Console.Write("Passwort eingeben um Löschen des Users zu bestätigen: "); inputPassword = Console.ReadLine(); // Eingelesenes Passwort durch Aufruf der Funktion Encrypt verschlüsseln: encryptedInputPassword = Encrypt(inputPassword, key); if (currentUser.Password == encryptedInputPassword) { users.DeleteUser(currentUser); currentUser = null; passed = false; } } break; case ConsoleKey.I: Console.Write("\nCurrent Users: \n"); Console.Write(users.GetUserList()); Console.ReadKey(); break; } } }