vCaptcha
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.
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 clientfails
Default: 10 - max fails allowed per userIdfailMemory
Default: 60 * 60 * 6 - Period of time before fails count resets
create(options, callback)
options <Object>
userId
Required: unique client identifierexpiresIn
Default: 60 * 2language
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 IDdata
base64 pictures arrayphrase
explanation to solve the captchanames
pictures to find to solve the captcha, to create your own phrase
count
fail count
solve(options, callback)
options <Object>
userId
Required: unique client identifierunique
Required: captcha ID to solvesolution
Required: guessed solution provided by the client.
callback <Function>
returns(valid)
valid <Boolean>
whether or not captcha is solved
Example
Try it on RunKit.
// INITIALIZEconst redis = ;const client = redis;const vCaptcha = client fails = 10 failMemory = 60 * 60 * 6; // CREATE A NEW CAPTCHAvCaptcha; // SOLVE CAPTCHAvCaptcha;
Client use
Example with Angular template.
Too many fails, come back later. {{ captcha.phrase }}
Credit
Pictures are taken from deprecated VisualCaptcha.