验证用户名和密码,输入三次不正确就锁定账号

using System;
using System.Globalization;

class Program
{
    public static void Main(string[] args)
    {
        var count = 3;
        for (int i = 0; i < count; i++)
        {
            var username = GetString();
            var password = GetString();
            if (username == "zxl" && password == "zxl")
            {
                Print(username);
                Print(password);
                break;
            }
        }
        if (count == 3)
        {
            Print("lock");
        }
    } //Main函数结束


    #region 工具方法

    public static void Print(string obj, params object[] arg)
    {
        Console.WriteLine(obj, arg);
    }

    public static void Print(object obj)
    {
        Console.WriteLine(obj);
    }

    /// <summary>
    /// 获得一个int类型的值
    /// </summary>
    /// <returns></returns>
    public static int GetInt()
    {
        int i;
        while (true)
        {
            try
            {
                i = Convert.ToInt32(Console.ReadLine());
                break;
            }
            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        return i;
    }

    public static string GetString()
    {
        return Console.ReadLine();
    }

    public static double GetDouble()
    {
        double i;
        while (true)
        {
            try
            {
                i = Convert.ToDouble(Console.ReadLine());
                break;
            }
            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        return i;
    }

    #endregion
}

 

posted on 2017-09-28 14:35  靖康耻  阅读(366)  评论(0编辑  收藏  举报

导航