JSPM

vcaptcha-stateless

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q30056F
  • License MIT

Node.js captcha generator

Package Exports

  • vcaptcha-stateless

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (vcaptcha-stateless) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

vCAPTCHA

Simple but user-friendy Node.js stateless captcha generator. It makes the user pick up 2 pictures (in sequence) among several (5 by default). Should be enough for low security forms.

Pictures are taken from deprecated VisualCaptcha.

Getting Started

What it does :

  • generate base64 pictures to display in the client;
  • generate a phrase to help you pick up the right pictures;
  • generate pictures names only if you want a custom phrase;
  • generate a key, which is simply the encoded solution.

All this data must be passed to the client. The key must be sent back to the server along with the guessed solution.

Install

npm i --save vcaptcha-stateless

Usage

// INITIALIZE
const vCaptcha = require('vcaptcha')({ 
  secret: 'secret',
  maxFails: 10
});

// CREATE A NEW CAPTCHA
const captcha = vCaptcha.create({
  userId: '192.168.1.30', // unique ID of your choice
  language: 'fr', // 'en' or 'fr'
  length: 5,
  expiresIn: 60 * 2 // for 2 minutes
});

// SOLVE CAPTCHA
vCaptcha.solve({
  key: body.key,
  solution: body.solution
}, (valid, captcha) => {
  if (valid) {
    // user completed the captcha
    // captcha = undefined
  } else {
    // if maxFails is not reached, captcha = a new captcha
    // if maxFails is reached, captcha = null
  }
});

Client use

Example with Angular template.

<div class="captcha">
  <h5 *ngIf="error">Too many fails, come back later.</h5>
  <div *ngIf="!error" class="captcha-box">
    <label><span>{{ captcha.phrase }}</span></label>
    <ul class="thumbnails selector">
      <li *ngFor="let src of captcha.data; let i = index">
        <div class="thumbnail" [class.selected]="isSelected(i)" (click)="toggleSelect(i)">
          <img class="image" [src]="'data:image/png;base64,'+ src">
        </div>
      </li>
    </ul>
  </div>
</div>

vCAPTCHA preview