In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "how to use pure JavaScript to generate pictures or slider CAPTCHA function", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how to use pure JavaScript to generate pictures or slider CAPTCHA function" it!
Captchapng
CAPTCHA generation module realized by pure JavaScript.
Easy to install and less dependent:
Npm install captchapng
Example:
Var captchapng = require ('captchapng'); app.get (' / sign/captcha.png', function (req, res) {var captchaNumber = parseInt (Math.random () * 9000 + 1000) req.session.captcha = captchaNumbervar p = new captchapng (80 mine20, captchaNumber); / / width,height,numeric captchap.color (0,0,0,0); / / First color: background (red, green, blue, alpha) p.color (80,80,80,255) / / Second color: paint (red, green, blue, alpha) var img = p.getBase64 (); var imgbase64 = new Buffer (img,'base64'); res.writeHead (200,{ 'Content-Type':' image/png'}); res.end (imgbase64);})
Express + Captcha
CAPTCHA generation module designed for Express framework.
Installation & example:
$npm install captchaUsage (for Express 4) 'use strict'const express = require (' express') const session = require ('express-session') const bodyParser = require (' body-parser') const captchaUrl ='/ captcha.jpg'const captchaId = 'captcha'const captchaFieldName =' captcha'const captcha = require ('. / captcha'). Create ({cookie: captchaId}) const app = express () app.use (session ({secret: 'keyboard cat',resave: false,saveUninitialized: true) }) app.use (bodyParser.urlencoded ({extended: false})) app.get (captchaUrl, captcha.image ()) app.get ('/', (req, res) = > {res.type ('html') res.end (`
`)}) app.post ('/ login', (req, res) = > {res.type ('html') res.end (`
CAPTCHA VALID: ${captcha.check (req, req.body [captchaFieldName])}
`)}) app.listen (8080, () = > {console.log ('server started')})
Front-end slider verification
The front-end generation track is sent to the back-end verification, the input is simple, but it is easy to crack.
Thank you for your reading, the above is "how to use pure JavaScript to generate pictures or slider CAPTCHA function" of the content, after the study of this article, I believe you on how to use pure JavaScript to generate pictures or slider CAPTCHA function of this problem has a deeper understanding, the specific use of the need for you to practice verification. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.