1.1.5 • Published 2 years ago

@tokensuite/react-slider-captcha-v2-core v1.1.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

@tokensuite/react-slider-captcha-v2-core

Installation

Backend:

npm i @tokensuite/react-slider-captcha-v2-core

Usage

Express:

import {createCaptcha, verifyCaptcha} from '@tokensuite/react-slider-captcha-v2-core'; // or @tokensuite/react-slider-captcha-v2-core/lib/esm

app.get('/captcha/create', function (req, res) {
  sliderCaptcha.create()
    .then(function ({data, solution}) {
      req.session.captcha = solution;
      req.session.save();
      res.status(200).send(data);
    });
});

app.post('/captcha/verify', function (req, res) {
  sliderCaptcha.verify(req.session.captcha, req.body)
    .then(function (verification) {
      if (verification.result === 'success') {
        req.session.token = verification.token;
        req.session.save();
      }
      res.status(200).send(verification);
    });
});

For quick tryout in Next.js api:

import {createCaptcha, verifyCaptcha} from '@tokensuite/react-slider-captcha-v2-core'; // or @tokensuite/react-slider-captcha-v2-core/lib/esm
export let solution: number;

export default async function handler(req: any, res: any) {
  createCaptcha()
    .then((resp: any) => {
      solution = resp.solution;
      res.status(200).send(resp.data);
    })
    .catch((err: any) => {
      res.status(500).send(err);
    });
}

export default async function handler(req: any, res: any) {
  verifyCaptcha(solution, req.body).then(function (verification: any) {
    res.status(200).send(verification);
  });
}

Create captcha options

sliderCaptcha.create({option: value})

NameTypeDefaultDescription
imagebufferrandomly generated patternBackground image used for captcha - resized to 250x150
fillstring#000Color used in overlay of puzzle piece on background
strokestring#fffColor for outline of puzzle piece
strokeWidthstring0.4Puzzle piece outline width
opacitystring0.5Opacity of puzzle piece overlay on background
distortboolfalseApply distortion to the puzzle piece
rotateboolfalseApply a random rotation to the puzzle piece

Verify captcha options

sliderCaptcha.verify(captcha, {response, trail: {x, y}}, {option: value})

NameTypeDefaultDescription
tolerancenumber7Allowed deviation from true captcha value

Inspiration

Slider Captcha - A captcha library for web applications from adrsch (MIT License)

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago