captcha.js 523 B

123456789101112131415161718192021222324
  1. const express = require('express');
  2. const router = express.Router();
  3. const svgCaptcha = require('svg-captcha');
  4. const c = svgCaptcha.create();
  5. router.get('/', (req, res, next) => {
  6. let captcha = svgCaptcha.create({
  7. size: 4,
  8. ignoreChars: '0o1ilI',
  9. noise: 2,
  10. color: true,
  11. fontSize: 50,
  12. width: 100,
  13. height: 36
  14. });
  15. req.session.captcha = captcha.text.toLowerCase();
  16. res.type('svg');
  17. res.status(200).send(captcha.data);
  18. });
  19. module.exports = router;