using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication5 { class Program { public static string ReadPassword() { string password = ""; ConsoleKeyInfo info = Console.ReadKey(true); while (info.Key != ConsoleKey.Enter) { if (info.Key != ConsoleKey.Backspace) { Console.Write("*"); password += info.KeyChar; } else if (info.Key == ConsoleKey.Backspace) { if (!string.IsNullOrEmpty(password)) { // remove one character from the list of password characters password = password.Substring(0, password.Length - 1); // get the location of the cursor int pos = Console.CursorLeft; // move the cursor to the left by one character Console.SetCursorPosition(pos - 1, Console.CursorTop); // replace it with space Console.Write(" "); // move the cursor to the left by one character again Console.SetCursorPosition(pos - 1, Console.CursorTop); } } info = Console.ReadKey(true); } // add a new line because user pressed enter at the end of their password Console.WriteLine(); return password; } static void Main(string[] args) { Random numberMaker = new Random(); int number = numberMaker.Next(1, 100); Console.WriteLine("Please input your name below."); Console.Write("Name: "); string name = Console.ReadLine(); if (name == "") { Console.WriteLine("\nERROR"); name = "ERROR"; } Console.WriteLine("\nI'm thinking of a number between 1 and 100."); int guess = 0; do { Console.Write("Take a guess: "); guess = int.Parse(Console.ReadLine()); if (number > guess) { Console.WriteLine("\nToo low"); } else if (number < guess) { Console.WriteLine("\nToo high"); } else if (name == "Logan") { string PASSWORD = "998783"; Console.Write("\nPassword: "); string password = Console.ReadLine(); if (password == PASSWORD) { Console.WriteLine("\nAccess Granted."); Console.WriteLine("\nWelcome {0}.\n", name); int num1; int num2; string operand; float answer; Console.Write("\nPlease enter the first integer: "); num1 = Convert.ToInt32(Console.ReadLine()); Console.Write("Please enter an operand (+, -, /, *): "); operand = Console.ReadLine(); Console.Write("Please enter the second integer: \n"); num2 = Convert.ToInt32(Console.ReadLine()); switch (operand) { case "-": answer = num1 - num2; break; case "+": answer = num1 + num2; break; case "/": answer = num1 / num2; break; case "*": answer = num1 * num2; break; default: answer = 0; break; } Console.WriteLine(num1.ToString() + " " + operand + " " + num2.ToString() + " = " + answer.ToString()); } else { Console.WriteLine("\nERROR"); break; } } else { Console.WriteLine("\nYou win!"); } } while (number != guess); Console.ReadLine(); Console.WriteLine("Good bye, {0}.",name); Console.ReadLine(); } } }
string password = Console.ReadLine();
string password = ReadPassword();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)