你的位置:首页 > ASP.net教程

[ASP.net教程]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();