I am trying to place a captcha on the registration page of a website. How can I show a captcha in node.js?
Check out node-captcha-generator
It uses the MNIST Database to generate numerical captcha images. Pretty easy to integrate. I had used it on a previous website, it generates captcha images that look like this
Very simple usage as well. Here is an example for a GET request for generating a new Captcha image on each request (Express):
let Captcha = require('node-captcha-generator');
router.get('/imageGen', function(req, res, next) {
var c = new Captcha({
length:5, // Captcha length
size:{ // output size
width: 450,
height: 200
}
});
c.toBase64(function(err, base64){
base64Data = base64.replace(/^data:image\/png;base64,/, "");
base64Data += base64Data.replace('+', ' ');
console.log(base64Data);
binaryData = new Buffer(base64Data, 'base64').toString('binary');
if(err){
console.log("Captcha Error");
console.log(err);
}
else{
res.contentType('image/png');
res.end(binaryData,'binary');
}
});
});
Hope this answer helps, and unlike reCaptcha, no need for a HTTPS certificate for integrating in your website. Perfect for college/hobby projects
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With