1. 程式人生 > 其它 >node生成驗證碼

node生成驗證碼

技術標籤:node

node生成驗證碼

前言:
使用第三方庫 npm install --save svg-captcha
svg驗證碼

效果1:

在這裡插入圖片描述

效果2:

在這裡插入圖片描述

程式碼

const express = require('express');
const router = express.Router();
const svgCaptcha = require('svg-captcha');
// 直接是字母的
router.get('/', (req, res, next) => {
    const captcha = svgCaptcha.create({
        size:
6, ignoreChars: '0o1liO', noise: '3', color: true, background: '#c67728' }); req.session.captcha = captcha.text; res.type('svg'); res.status(200).send(captcha.data); }) // 數字計算的 router.get('/calculate', (req, res, next) => { const captcha = svgCaptcha.
createMathExpr({ size: 6, ignoreChars: '0o1liO', noise: '3', color: true, background: '#c67728' }); req.session.captcha = captcha.text; res.type('svg'); res.status(200).send(captcha.data); }) module.exports = router;