private static string HashPassword(string input) {
return SHA.ComputeSHA256Hash(input);
private static bool PasswordsMatch(string userInput, string savedTextFilePassword) {
string hashedInput = HashPassword(userInput);
bool doPasswordsMatch = string.Equals(hashedInput, savedTextFilePassword);
public static void Main() {
string myPassword = "password123";
string hashedSavedPassword = HashPassword(myPassword);
Console.WriteLine("The hashed version of the users password is: {0} (this is what gets saved to the text file)", hashedSavedPassword);
string userInputPassword = "password123";
Console.WriteLine("The hashed version of the good entered password is {0} (it should match the one in the text file)", HashPassword(userInputPassword));
string userInputPasswordFails = "not the correct password";
Console.WriteLine("The hashed version of the bad entered password is {0} (this will not match the one in the text file)", HashPassword(userInputPasswordFails));
if (PasswordsMatch(userInputPassword, hashedSavedPassword))
Console.WriteLine("The good Password is correct");
Console.WriteLine("The good Password is not correct");
if (PasswordsMatch(userInputPasswordFails, hashedSavedPassword))
Console.WriteLine("The bad Password is correct");
Console.WriteLine("The bad Password is not correct");