Socket
Socket
Sign inDemoInstall

tencent-captcha

Package Overview
Dependencies
26
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tencent-captcha

A simple library of captcha based on tencentcloud-sdk-nodejs.


Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Install size
34.3 MB
Created
Weekly downloads
 

Readme

Source

tencent-captcha

A simple library of captcha based on tencentcloud-sdk-nodejs.

Install

Using npm

npm install tencent-captcha --save

Usage

Browser usage

You can see the client access CAPTCHA from this document for details.

Using TencentCaptcha JSSDK
<script src="https://ssl.captcha.qq.com/TCaptcha.js"></script>
Create instance of TencentCaptcha, include callback function
var T_Captcha = new TencentCaptcha('your_tencentcloud_application_ID', function(res) {
    //a callback from TencentCaptcha server
    if (res && res.ret == 0) {
        //success
        T_Captcha.destroy();
        //ajax request the relevant verification interface of the server.
        //you can see the following step [Node.js usage] to perform server-side validation.
    } else {
        //failure
    }
});
Man-machine verification enabled
T_Captcha.show();

Node.js usage

You can see the validation interface of Tencent Captcha from this document for details.

const TencentCaptcha = require('tencent-captcha');
const captcha = new TencentCaptcha({
    secretId: 'your_tencentcloud_API_secretId',
    secretKey: 'your_tencentcloud_API_secretKey',
    appId: 'your_tencentcloud_application_ID',
    appSecretKey: 'your_tencentcloud_application_secretKey'
});
try {
    const res = await Captcha.validate(ticket, randstr, ip);
    if (res.CaptchaCode === 1) {
        //success
    } else {
        //failure
    }
} catch(e) {
    //catch tencentcloud-sdk-nodejs exception
}

You can get related secret ID and key from Tencent Cloud Console.

Method

Create an instance of TencentCaptcha in server

new TencentCaptcha(options);

  • options => tencentcloud-sdk-nodejs'config object.(required)

options field description

  • secretId => {String} tencentcloud API secretId.(required)
  • secretKey => {String} tencentcloud API secretKey.(required)
  • appId => {String} tencentcloud application ID.(required)
  • appSecretKey => {String} tencentcloud application secretKey.(required)

Using the following API to ensure the ticket is valid

captcha.validate(ticket, randstr, ip)

  • ticket => {String} user authentication ticket from client's callback function.(required)
  • randstr => {String} random string from client's callback function.(required)
  • ip => {String} User ip.(required)

The Return value of this method is a promise, you can use async-await synchronizing code. You can see data structure returned from the interface of Tencent Captcha by document.

License

tencent-captcha is MIT licensed.

Keywords

FAQs

Last updated on 13 May 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc