svg-captcha生成验证码——koa2.x

1、安装引入验证码模块

 npm install --save svg-captcha

2、生成随机数验证码

router.get('/code',async (ctx) => {
    var captcha = svgCaptcha.create({    //这种生成的是随机数验证码
      size:4,    //验证码长度
      fontSize:50,   //字体大小
      width:100,
      height:40,
      background:'#cc8801'
    });
    console.log(captcha.text);
    ctx.response.type = 'image/svg+xml';
    ctx.body = captcha.data;
  });

在这里插入图片描述
3、生成加法验证码:
svgCaptcha.createMathExpr()
在这里插入图片描述

你可能感兴趣的:(koa,服务器,验证码,svg-captcha)