Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

captcha-generator-alphanumeric

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

captcha-generator-alphanumeric

An NPM package to generate alphanumeric captcha images

  • 1.10.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
138
increased by10.4%
Maintainers
1
Weekly downloads
 
Created
Source

Captcha Generator

Captcha Generator is a Node library for quickly and easily generating captcha images. Forked from HaileyBot/captcha-generator for colorful alphanumeric captchas.

Sample

Installation

Use the package manager npm to install Captcha Generator

npm i captcha-generator-alphanumeric

Usage

Basic

// Import the module
const Captcha = require("captcha-generator-alphanumeric").default;

// Create a new Captcha object
//  - Optional argument to specify image height (250 to 400px, default 250)
//    - Image width is 400px
//  - Returned object will contain 4 properties
//    - "PNGStream" is a stream object for the image file in PNG format
//    - "JPEGStream" is a stream object for the image file in JPEG format
//    - "dataURL" is a data URL containing the JPEG image data
//    - "value" is the 6 character code the image contains
let captcha = new Captcha();
console.log(captcha.value);

Save to file example

const path = require("path"),
	fs = require("fs"),
	Captcha = require("captcha-generator-alphanumeric").default;

let captcha = new Captcha();
captcha.PNGStream.pipe(fs.createWriteStream(path.join(__dirname, `${captcha.value}.png`)));
captcha.JPEGStream.pipe(fs.createWriteStream(path.join(__dirname, `${captcha.value}.jpeg`)));

Discord Example

This example assumes you already have the core framework of a Discord Bot set up

const Captcha = require("captcha-generator-alphanumeric").default;

// Use this function for blocking certain commands or features from automated self-bots
function verifyHuman(msg) {
	let captcha = new Captcha();
	msg.channel.send(
		"**Enter the text shown in the image below:**",
		new Discord.MessageAttachment(captcha.JPEGStream, "captcha.jpeg")
	);
	let collector = msg.channel.createMessageCollector(m => m.author.id === msg.author.id);
	collector.on("collect", m => {
		if (m.content.toUpperCase() === captcha.value) msg.channel.send("Verified Successfully!");
		else msg.channel.send("Failed Verification!");
		collector.stop();
	});
}

License

This project is licensed under GPL-3.0

Keywords

FAQs

Package last updated on 01 Dec 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc