npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vcaptcha

v1.1.0

Published

Node.js captcha generator

Downloads

6

Readme

vCaptcha

Build Status Coverage Status Known Vulnerabilities codebeat badge

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


vCAPTCHA preview


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 hashed solution. This SHOULD NOT be passed to the client.
  • generate a unique identifier for each captcha, to help you retrieve it.

What it does if you pass a Redis Client :

  • store keys.
  • count & limit fails based on unique user identifier you provide
  • expire captchas.

Install

npm i --save vcaptcha

API

require('vcaptcha')(options)

  • Initialize vCaptcha
  • options <Object>
    • client Required: Redis client
    • fails Default: 10 - max fails allowed per userId
    • failMemory Default: 60 * 60 * 6 - Period of time before fails count resets

create(options, callback)

  • options <Object>
    • userId Required: unique client identifier
    • expiresIn Default: 60 * 2
    • language Default: 'en' - also supported: 'fr'
    • length Default: 5 - number of pictures to send to the client
  • callback <Function> returns (err, captcha, count)
    • captcha <Object>
      • unique captcha ID
      • data base64 pictures array
      • phrase explanation to solve the captcha
      • names pictures to find to solve the captcha, to create your own phrase
    • count fail count

solve(options, callback)

  • options <Object>
    • userId Required: unique client identifier
    • unique Required: captcha ID to solve
    • solution Required: guessed solution provided by the client.
  • callback <Function> returns (valid)
    • valid <Boolean> whether or not captcha is solved

Example

Try it on RunKit.

// INITIALIZE
const redis = require('redis');
const client = redis.createClient();
const vCaptcha = require('vcaptcha')({
  client,
  fails = 10,
  failMemory = 60 * 60 * 6
});

// CREATE A NEW CAPTCHA
vCaptcha.create({
  userId: '192.168.1.30',
  expiresIn: 60 * 2,
  language: 'en',
  length: 5
}, (err, captcha, count) => {
  // captcha can be sent to your client form
});

// SOLVE CAPTCHA
vCaptcha.solve({
  userId: '192.168.1.30',
  unique: body.unique,
  solution: body.solution
}, valid => {
  if (valid) {
    // user completed the captcha
  }
});

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>

Credit

Pictures are taken from deprecated VisualCaptcha.