Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

captcha-genjs

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

captcha-genjs

Captcha generator with verification by secret key

  • 1.1.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

Welcome to Captcha Generator

Unfortunately, there is no Typescript support yet. If you need ES6 types and support, then please contact me, and I will do it. ;)

Initialization:

import CaptchaJs from 'captcha-genjs';

const SECRET = "ABC";
const Captcha = CaptchaJs.create(SECRET);

SECRET is required to sign the response to your captcha. Even if someone finds out your secret key, it will not be possible to find out the answer to the captcha. But the secret key will make it possible to check the correctness of the captcha.

Layout

To create a Canvas layer, you need to call the create Canvas method.

Captcha.createCanvas(150, 50);

We have just created a layer with default values of 50x150px. They are accepted by default, if you do not want to configure your captcha in detail, then using this method makes no sense.

Props
  • width - px: number;
  • height - px: number;
  • alphabet - object;
let alphabet = {
    alphabet: "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789", // for generation
    len: 6 // len generation
};
  • color - hex, rgb: string;
  • size - px: number; font-size

Pay attention.

It is not necessary to transmit data by an object, therefore, if you want to transmit color, you need to transmit width, height and others. This is a temporary measure in future versions in plans to get rid of this ugly design.

Generate captcha

In order to generate a captcha, you need to call the appropriate method. In the method parameters, you can pass the code that will be printed on the layer. If nothing is transmitted, then a random code generated based on your alphabet and length will be printed on the layer.

let result = Captcha.generate();

Props

  • code

Return

  • url: img base64. Can use for src at html.
  • hash: string; An encrypted response to a captcha. Can be use in the client
  • code: string; The code that is printed on the picture. Use it if you need to implement your own validation.
result = {
  url: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAACWCAYAAACcsttJAAAABmJLR0QA/wD/AP+gvaeTAAAMO0lEQVR4nO2ce5RVVR3HP3OHxwzvgRFWAwIqJEYab3oQhJlF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M5onFAg2YdNKKacNMlEO0zjsSqVPze4FtVsWLsthmQK4o6opINKtC7sj2nO15dhJBjWD0kJ8giTmQVLis54b7xMBw8iCzsrr/8psv6sdQbyjqDFoPdmIG9PtpG5map70YifVkcrHouQs5UpTqBmFppk22ImNJfJVGTzhd4fnExBOiLtMpzMbeV7CDlgc8PeYBp9TZAN1RU5Q12sowKtgOhsHSdR1bdFUftbkYmRbm5CGw1ao8lXX4rQ4uKuOOvf9+OY51XW933W5wEr04vRatPu6ZbexREUkgoVqRyEnnQiWqIYaZZM73GfhJpxKNmWosDZRBSnDTv1uxP/peXp4gTe64ujKEYhHjvs8000QfND5E/3RzHbUtQ3zLY6AmmvnemU2oMWaGXdDDQJ5Uk8D68zmtzpjRbR2J8foGjkduSnbwN+RMB2iBSJIEvil6RnFgyQ9voyWlL+KlIA2dj1NovYlaVpYyTxV6Omm2YoepORt7H1IvP9w2QJcurSTnOyaNwhpVNPhnz7vcQuHMgk24le9Jw2VhI7RZdJrkEB8JjoZaqemHsWK9MsRgNk2h2vzmT/XcFz+R952XJH1OkzukEzW+xFW6YKnnvwXmpScLRCzetC+0Shvj76FLLGR9knIigonfKSiSzTE9XKR+bJ+1Dn6ZcDgVIhJorTE1myNeT5WzWCqEQj5nVowcA88vBVCGFohnZX7kGrHVahdz7k5Xu0wmAWaBeKuOftq9rCYBeoGoViCuYdjfFohpYEnkWBOb/1iwVBBzSTewat6Cno5laEdijYIdUVFHiBRqKA3nyktpeQmUX9WeFSNN48gsIzefPuoGRoh5ZDvUQC24TylQha7pTXb50tOP4L7xMz/gR0v4sAAAAASUVORK5CYII=',
  hash: '4bc73e67641d302164b31d8316e421b89adb45fbb7d90a80dae2f1b5f243bd43',
  code: 'VIO4OV'
}

Validation

console.log(Captcha.checkCode(result.code, result.hash));

Props

  • code the answer to the captcha that came to you from the client
  • hash from generate

Return boolean

Keywords

FAQs

Package last updated on 14 Feb 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc