Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #15

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/captcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function filter(im) {
om.copy(im)
}

async function captcha(size) {
async function captcha(letters,size) {
const rb = await urandom(size + 200 + 100 * 4 + 1 + 1)
const l = Buffer.alloc(size)
const swr = Buffer.alloc(200)
Expand All @@ -148,9 +148,9 @@ async function captcha(size) {
let p = 30

for (let n = 0; n < size; n++) {
l[n] %= 25
l[n] %= letters.length -1;
p = letter(l[n], p, im, swr, s1, s2)
l[n] = LETTERS.charCodeAt(l[n])
l[n] = letters.charCodeAt(l[n])
}

line(im, swr, s1)
Expand Down Expand Up @@ -192,9 +192,9 @@ function makegif(im, gif, style) {
gif.fill('\x01\x11\x00;', GIF_SIZE - 4)
}

async function generate({ size = SIZE, style = -1 } = {}) {
async function generate({ size = SIZE, style = -1, letters = LETTERS } = {}) {
const gif = Buffer.alloc(GIF_SIZE)
const { im, l } = await captcha(size)
const { im, l } = await captcha(letters,size)
makegif(im, gif, style)

return {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "trek-captcha",
"version": "0.4.0",
"version": "0.5.0",
"description": "A Lightweight Pure JavaScript Captcha for Node.js. No C/C++, No ImageMagick, No canvas.",
"repository": "trekjs/captcha",
"author": {
Expand Down
6 changes: 6 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ test('should return an object and include token and buffer', async t => {
t.is(token.length, 5)
t.is(buffer.length, 17646)
})
test('random numbers should be from letters', async t => {
const { token } = await captcha({letters:'1'})
console.log(token);
t.is(token, '11111')
})