npm.io
1.0.2 • Published 2 years ago

@mr_fozan/captcha

Licence
ISC
Version
1.0.2
Deps
4
Size
23.1 MB
Vulns
1
Weekly
0

Captcha

npm package

Captcha is a Node.js module that allows you to create and manage captcha sessions efficiently.

Quick Start

Here's a quick example of how to get started with the Captcha library:

CodeSnap

const Captcha = require('@mr_fozan/captcha');

// Create a new captcha instance with the desired number of variations
const captcha = new Captcha({ variations: 3 });

// Generate a new captcha
captcha.generate().then(result => {
  console.log('Generated Captcha:', result);

  // Example of verifying user input
  const isValid = captcha.verify(result.id, result.answer);
  console.log('Captcha verification result:', isValid);
}).catch(err => {
  console.error('Error generating captcha:', err);
});

Installation

Using NPM:

npm install @mr_fozan/captcha

Using Yarn:

yarn add @mr_fozan/captcha

Documentation

Creating a Captcha
const Captcha = require('@mr_fozan/captcha');

// Create a new captcha instance with the desired number of variations
const captcha = new Captcha({ variations: 3 });

// Generate a new captcha
const result = await captcha.generate();
console.log(result);

Response Structure:

  • id: Unique identifier for the captcha
  • answer: The correct answer for the captcha
  • variations: Array of answer options, including the correct one
Verifying Captcha Input
const Captcha = require('@mr_fozan/captcha');

// Create a new captcha instance
const captcha = new Captcha({ variations: 3 });

// The captcha ID and user input to verify
const captchaId = '001'; // Use the actual ID from the generated captcha
const userInput = '🍫';  // User's input for verification

// Verify the user's input
const result = captcha.verify(captchaId, userInput);
console.log(result);

Verification Parameters:

  • id: Unique identifier for the captcha
  • userInput: The response provided by the user

Verification Response:

  • response: Boolean indicating whether the captcha is correct (true or false)

Contributors

Contributors

License

This project is licensed under the MIT License.

Keywords