単純なログイン/認証コンソールアプリケーションを作成しようとしています。たとえば、パスワードとして文字列testpwdがあり、ユーザーがパスワードの入力を開始した瞬間の時間をミリ秒単位でカウントし、その数を出力する必要があります。ユーザーが機能を使用してキーボードから入力を開始するたびに、各ユーザーがパスワードを入力するのにかかる秒GetTickCount
数。
どうすればよいかわかりませんが、私が何とかできたのは、以下のコードだけです。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace LoginSystem
{
class LSystem
{
static void Main(string[] args)
{
Console.WriteLine("Hello! This is simple login system!");
Console.Write("Write your username here: ");
string strUsername = Console.ReadLine();
string strTUsername = "testuser";
if (strUsername == strTUsername)
{
Console.Write("Write your password here: ");
Console.ForegroundColor = ConsoleColor.Black;
string strPassword = Console.ReadLine();
string strTPassword = "testpwd";
if (strPassword == strTPassword)
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("You are logged in!");
Console.ReadLine();
}
else
{
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("Bad password for user: {0}", strUsername);
Console.ReadLine();
}
}
else
{
Console.WriteLine("Bad username!");
Console.ReadLine();
}
}
}
}