c#验证码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 验证码字符串做法
{
    class Program
    {
        static void Main(string[] args)
        {
            //定义一组字符串
            string[] s= new string[62]
            {"0","1","2","3","4","5","6","7","8","9",
                "a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s",
             "t","u","v","w","x","y","z",
                "A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q",
            "R","S","T","U","V","W","X","Y","Z"
            };
            string a="";//定义一个a的字符变量,值为空
            Random ran = new Random();
            for (int i = 0; i < 4;i++ )
            {
                int suijishu = ran.Next(0, 62);
                a+= s[suijishu];//将随机产生的四个字符连成一个字符串表示验证码
            }
            Console.WriteLine("验证码:"+a);
            string b = a.ToUpper();//后台执行把所得的字符串全部转换为大写
            Console.Write("请输入验证码:");
            string r = Console.ReadLine();
            string q = r.ToUpper();//将用户输入的字符串全部转换为大写
            if (q == b)
            {
                Console.WriteLine("验证成功!");
            }
            else
            {
                Console.WriteLine("输入错误!");
            }
            


            Console.ReadLine();
        }
    }
}
原文地址:https://www.cnblogs.com/fengsantianya/p/5511272.html