// This method is called everytime the user enters a password. internal bool Login(string userID, string password) { if (password == _PASSWORD_String) { Console.WriteLine("\nCongratulations!! You logged in successfully!!"); return true; } ++_passwordTriesInt; if (_passwordTriesInt > 2) { // Now there have been three failed attempts to enter the correct password. // It's time to raise the alert message. // Make sure to check that there is at least one subscriber! if (OnPasswordAlert != null) { // TODO: Raise the OnPasswordAlert event by passing in an instance of // the PasswordAlertEventArgs class. Be sure // to store the user id in the instance. The user id is contained in the // variable "userID". PasswordAlertEventArgs e = new PasswordAlertEventArgs(userID); OnPasswordAlert(this, e); } } // Another failed attempt to enter the correct password. return false; }
private void DisplayPasswordAlert(object sender, PasswordAlertEventArgs e) { // Save the current color of the characters. ConsoleColor originalForeGroundColor = Console.ForegroundColor; // Change the color of the characters to Red. Console.ForegroundColor = ConsoleColor.Red; // TODO: Complete the Console.Writeline method below by passing in the user id // that is stored in the PasswordAlertEventArgs parameter. Console.WriteLine( "ALERT to {0}: Three attempts have been made to crack your password!!" ,); _passwordAlertBool = true; // Reset the color of the characters to their original color. Console.ForegroundColor = originalForeGroundColor; }