PHP Classes

File: test/js/test.js

Recommend this page to a friend!
  Classes of Nikos M.   Simple PHP Captcha Library   test/js/test.js   Download  
File: test/js/test.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Simple PHP Captcha Library
Show images to verify humans with math expressions
Author: By
Last change: v.2.6.0

* custom pattern callback instead of imagedata
Date: 8 days ago
Size: 1,795 bytes
 

Contents

Class file image Download
"use strict"; const SimpleCaptcha = require('../../src/js/SimpleCaptcha.js'); const echo = console.log; const tile = JSON.parse(require('fs').readFileSync('../tile.json')); function tile_pattern(x, y) { x = x % tile.width; y = y % tile.height; if (0 > x) x += tile.width; if (0 > y) y += tile.height; const i = (x + y*tile.width) << 2; return [tile.image[i ], tile.image[i+1], tile.image[i+2]]; } async function test() { const captcha = (new SimpleCaptcha()) .option('secret_key', 'SECRET_KEY') .option('secret_salt', 'SECRET_SALT_') .option('num_terms', 2) .option('max_num_terms', 3) // -1 means constant num_terms .option('min_term', 1) .option('max_term', 21) .option('color', 0x121212) // text color .option('background', 0xffffff) // background color ; captcha.reset(); captcha.option('difficulty', 2); // 0 (easy) to 3 (difficult) captcha.option('distortion_type', 1); // 1: position distortion captcha.option('color', [0xff0000, 0xffff00, 0x0000ff, 0x00ff00]); // text color gradient captcha.option('background', /*0x1Da1C1*/tile_pattern); // background color/pattern echo(await captcha.getCaptcha()); echo(); echo(await captcha.getHash()); echo("\n"); captcha.reset(); captcha.option('difficulty', 2); // 0 (easy) to 3 (difficult) captcha.option('distortion_type', 2); // 2: scale distortion captcha.option('color', 0xffffff); // text color captcha.option('background', [0xff0000, 0xffff00, 0x00ff00, 0x0000ff]); // background color gradient echo(await captcha.getCaptcha()); echo(); echo(await captcha.getHash()); } echo('SimpleCaptcha.VERSION ' + SimpleCaptcha.VERSION); test();