• 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)
            {
                //定义一组字符串 验证码需要26个英文大小写和0~9的数字
                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(62);//数组里有62个字符串,创建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//如果不一样,则输入错误,外部也可以加个无限循环,当输入错误时重新输入,成功时if下面加break跳出
                {
                    Console.WriteLine("输入错误!");
                }
                
    
    
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    吉他音阶笔记(以C调为基准)
    小程序页面跳转问题
    Adobe-premierej剪辑视频分辨率问题及格式转换画面质量分辨率
    关于ps抠图问题,制作公章,公章的复制
    premiere视频剪辑关于导出视屏分辨率的问题
    最后一个单词的长度
    10.两个链表的交叉
    软件工程——个人总结
    软件工程——团队专业4
    软件工程——团队答辩
  • 原文地址:https://www.cnblogs.com/zyg316/p/5514741.html
Copyright © 2020-2023  润新知