/simple-captcha-generator

Generate a simple captcha string and or captcha image.

Primary LanguageJavaScript

simple-captcha-generator

Generate a simple captcha string and or captcha image.

Installation

Type npm i simple-captcha-generator in your cmd to install the package

create captcha:

const { Captcha } = require("simple-captcha-generator");
const captcha = new Captcha();

Usage:

const { Captcha }= require('simple-captcha-generator');
let captcha = new Captcha();


(async () => {
    console.log(captcha.currentString);
    console.log(await captcha.image(captcha.currentString));
})();
How to set string length?

You can have have a min length of 5 and a max length of 10. When no length is specified it will default to 5. Every length above 10 will default to 10.

const captcha = new Captcha(5);

Options:

.currentString string

Returns a generated string with the given length
Example: '0e6ji'

.length int

Returns the given length
Example: 8

.image() Buffer

Returns and image buffer of the generated captcha (Promise so use await!)
Usage

captcha.image(captcha.currentString) //Return image buffer of current generated string

Example images: