Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require('express')
- const captchaGenerator = require('captchagen')
- const port = 3000
- const app = express()
- app.get('/', (req, res) => {
- const russianAlphabet = 'абвгдеёжзийклмнопрстуфхцчшщъыьэюя'
- const captchaLength = 6
- let captchaText = ''
- while (captchaText.length < captchaLength) {
- captchaText += russianAlphabet[Math.floor(Math.random() * russianAlphabet.length)]
- }
- const captcha = captchaGenerator.create({
- text: captchaText
- })
- console.log(captcha.text())
- captcha.generate()
- res.set('Content-Type', 'image/png')
- res.send(Buffer.from(captcha.buffer()))
- })
- app.listen(port, () => {
- console.log(`Example app listening on port ${port}`)
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement