.NETCore生成验证码

添加VerifyCode跟VerifyCodeType类

 public  class VerifyCode
    {
   
        /// <summary>
        /// 验证码
        /// </summary>
        public string Code {
    get; set; }

        /// <summary>
        /// 验证码数据流
        /// </summary>
        public byte[] Image {
    get; set; }
    }
    public enum VerifyCodeType
    {
   
        NUM,
        CHAR
    }

添加VerifyCodeHelper类

  public static class VerifyCodeHelper
    {
   
        /// <summary>
        /// 获取验证码
        /// </summary>
        /// <param name="n">验证码数</param>
        /// <param name="type">类型 0:数字 1:字符</param>
        /// <returns></returns>
        public static VerifyCode CreateVerifyCode(int n, VerifyCodeType type)
        {
   
            //宽、高,字体大小
            int codeW = 74;
            int codeH = 36;
            int fontSize = 16;

            //初始化验证码
            string charCode = string.Empty;

            switch (type.ToString())
            {
   
                case "NUM":
                    charCode = CreateNumCode(n);
                    break;
                default:
                    charCode = CreateCharCode(n);
                    break;
            }

            //颜色列表
            Color[] colors = {
    Color.Black, Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Brown, Color.DarkBlue };

            //字体列表
            string[] fonts = {
    "Times New Roman", "Verdana", "Arial", "Gungsuh" };

            //创建画布
            Bitmap bitmap = new Bitmap(codeW, codeH);
            Graphics graphics = Graphics.FromImage(bitmap);
            graphics.Clear(Color.White);

            Random random = new Random();

            //画躁线
            for (int i = 0; i < n; i++
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值