我正在尝试制作一个简单的登录/身份验证控制台应用程序,例如我有一个字符串 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();
}
}
}
}