我正在製作一個c#控制檯應用程序,並且想添加一個登錄系統。如何將C#控制檯連接到數據庫?
我有這樣的代碼已經:
Start:
Console.Clear();
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Enter Username.");
string strUsername = Console.ReadLine();
string strTUsername = "Test";
if (strUsername == strTUsername)
{
Console.Clear();
Console.WriteLine("Enter Password");
Console.ForegroundColor = ConsoleColor.Gray;
string strPassword = Console.ReadLine();
string strTPassword = "Test";
if (strPassword == strTPassword)
{
Console.Write("Logging in.");
Thread.Sleep(1000);
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("The password you entered is wrong.");
Thread.Sleep(2000);
goto Start;
}
}
else
{
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("The username you entered is wrong.");
Thread.Sleep(2000);
goto Start;
}
我想,使其允許多個用戶名和密碼就可以進入,將工作。
到目前爲止,它只是接受用戶名和密碼'測試',但我想鏈接到另一個文件充滿用戶名和密碼,我可以使用,而不是'測試'。
任何幫助你可以給我或提供的是有用的謝謝!
無論如何,如果我可以輸入多個用戶名和特定於不同配置文件的密碼,那麼這對我很有用。 – Drips
你會因爲使用'goto'而被釘十字架。 –
我還能使用什麼?大聲笑 – Drips