C#解决验证码问题

时间:2023-03-09 17:08:07
C#解决验证码问题

string ss = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
            Random a = new Random();
            int b;
            string yan = "";
            for (int i = 0; i < 4; i++)
            {
                b = a.Next(62);
                yan += ss.Substring(b, 1);
            }
            Console.WriteLine("验证码是:" + yan);
            Console.Write("请输入验证码:");
            string c = Console.ReadLine();
            if (c.ToUpper() == yan.ToUpper())
            {
                Console.WriteLine("验证码正确!");
            }
            else
            {
                Console.WriteLine("验证码错误!");
            }
            Console.ReadLine();