private void EstablishAccount() { Console.Clear(); bool done = false; while (!done) { string userName = ""; Console.Write("\nEnter a user name, then press (enter): "); userName = Console.ReadLine(); // if the username is unique in the dictionary if (!userAndPassword.ContainsKey(userName)) { userAndPassword.Add(userName, null); Console.Write("\nNow the password, then press (enter): "); string password = HideTextAsEntered(); password += salt; password += userName.GetHashCode(); password = CryptoStuff.GetHashedString(password); //stores the hashed password into the dictionary userAndPassword[userName] = password; done = true; } else // If the username is already taken { var originalColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("\nThat username already exists!"); Console.ForegroundColor = originalColor; Console.Write("\nWould you like to try again (y/n): "); bool finished = false; do { var answer = Console.ReadKey(true); switch (answer.Key) { case ConsoleKey.Y: Console.Write("y"); Console.WriteLine("\n\nGreat, try a different username this time!"); finished = true; break; case ConsoleKey.N: Console.Write("n"); finished = true; done = true; break; default: break; } } while (!finished); } } }
private void RealTimeHashDemo() { Console.Clear(); int initialConsoleWidth = Console.WindowWidth; int hashLength = 128; Console.CursorTop = hashLength / initialConsoleWidth + 2; Console.WriteLine($"Enter your text below to see it hashed in real time:\n"); string toScreen = CryptoStuff.GetKeyPressesRealTimeHashDisplay(); }
private void AuthenticateUser() { Console.Clear(); Console.Write("\nEnter the username you want to authenticate: "); string testUsername = Console.ReadLine(); if (userAndPassword.TryGetValue(testUsername, out string value)) { var originalColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Username {testUsername} is a registered user.\n"); Console.ForegroundColor = originalColor; Console.Write("Enter the password: "******"The hascode for {testUsername} is {testUsername.GetHashCode()}"); string testHash = CryptoStuff.GetHashedString(testPassword); if (testHash == userAndPassword[testUsername]) { originalColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"User {testUsername} has been authenticated!"); Console.ForegroundColor = originalColor; } else { originalColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"User {testUsername} has NOT been authenticated!"); Console.ForegroundColor = originalColor; } Console.Write("\nEnter any key to continue: "); Console.ReadKey(); } else { var originalColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"\nUsername {testUsername} isn't a registered user."); Console.ForegroundColor = originalColor; Console.Write("\nEnter any key to continue: "); Console.ReadKey(); } }