This is a simple demo on how we can use Cloudflare workers with KV to create our own simple captcha. It uses pure JS with Cloudflare Workers and KV without any external packages.
https://captcha-worker.cergo.workers.dev
- It creates a temporal UID and a corresponding captcha value, per request and save them in KV
{UID: CAPTCHA_VALUE}
(expires after 60 seconds) - It generates an image from a free text-over-image from https://textoverimage.moesif.com and load it
3. It compares the UID and the entered captcha value then generate an encrypted token.
- Create your own text-over-image backend because the used free one has the captcha text value in its url!
- Save the token to a database to use it later or to use it as a session token.
- Find your own better way to encrypt and generate the token
- You cannot control
DOM
in Cloudflare, so I was not able to useCanvas
to generateBase64
image data and I didn't want to pass the Captcha value just as a String in the HTML, that is why I used an external API to generate the image.
This has been submitted as a participation in Cloudflare Summer Challenge