diff --git a/helpers/captchagenerate.js b/helpers/captchagenerate.js index 7b7cb8f8..c66b8d17 100644 --- a/helpers/captchagenerate.js +++ b/helpers/captchagenerate.js @@ -17,16 +17,30 @@ module.exports = (text, captchaId) => { text = text.split(''); //array of chars const x = gm(200, 80, '#fff') .fill('#000') - .fontSize(80) + .fontSize(70) + let lastx = 0; for (let i = 0; i <6; i++) { - x.drawText(i*30, 55+rr(0,10), text[i]) - } - for (let i = 0; i <4; i++) { - const shape = getShape(); - x.strokeWidth(rr(3, 5)) - x.drawCircle(shape.x1, shape.y1, shape.x2, shape.y1) + x.drawText(lastx, 50+rr(0,10), text[i]) + switch (text[i]) { + case 'w': + case 'm': + lastx += 40; + break; + case 'i': + case 'f': + case 'l': + case 'j': + case 't': + lastx += 15; + break; + default: + lastx += 30; + break; + } } - x.wave(10, rr(50,80)) + const recy1 = rr(30,50) + x.drawRectangle(rr(5,10), recy1, rr(190,195), recy1+5) + .wave(10, rr(80,120)) .blur(1, 2) .crop(200, 80, 0, 0) .quality(30) diff --git a/models/pages/captcha.js b/models/pages/captcha.js index ef35b636..abbc84d8 100644 --- a/models/pages/captcha.js +++ b/models/pages/captcha.js @@ -1,6 +1,6 @@ 'use strict'; -const crypto = require('crypto') +const { randomBytes } = require('crypto') , Captchas = require(__dirname+'/../../db/captchas.js') , generateCaptcha = require(__dirname+'/../../helpers/captchagenerate.js'); @@ -8,9 +8,10 @@ module.exports = async (req, res, next) => { // if we got here, they dont have a cookie so we need to // gen a captcha, set their cookie and redirect to the captcha - const text = crypto.randomBytes(20).toString('hex').substring(0,6); let captchaId; try { +// const text = await randomBytes(3).toString('hex').substring(0,6); + const text = Math.random().toString(36).substr(2,6); captchaId = await Captchas.insertOne(text).then(r => r.insertedId); //get id of document as filename and captchaid await generateCaptcha(text, captchaId); } catch (err) {