Implement a CAPTCHA with Azure Functions

CAPTCHA’s are those things that site administrators love because they stop comment and form spam but user hate because they are impossible to read. Regardless though, they have become a mainstay in Internet usage, particularly on websites that allow for unauthenticated feedback. CAPTCHA’s are intended to prevent automated responses from computers by generating a test that is easy for a human to solve by more difficult for a computer to solve.

This function creates a graphic with randomly generated digits and asks the user to type in those digits in a specific order.

Sample CAPTHCHA

Each CAPTCHA is only valid for one attempt. After a failed attempt, a new CAPTCHA is generated.

Azure Functions provide a convenient way of creating scalable, serverless “functions”. Functions enable applications developers to write event-driven code (ie. “functions”) than can be triggered by timers, manual integration, HTTP requests, service buses, message queues and many other integration points. These functions can be written in a number of different languages including C#, NodeJS (which this function uses), Python, PHP and a myriad of of other languages. CAPTCHAs are a good candidate for a function because they are called via HTTP requests and can be responded to via requests.

If you have not already done so create an Azure Function. There are a few ways to do this — either in the portal, through the Azure CLI, or with Visual Studio. The Azure Portal is probably the easiest way to do it.

This function is using NodeJS to create and validate a CAPTCHA’s. NodeJS does not explicitly support any graphics libraries, so this implementation uses the NPM package GM, which is a wrapper around the GraphicsMagick CLI utility. Results from validate CAPTCHAs are stored in Azure Table Storage and can be sent via email using SendGrid.

Interested? Checkout this project on GitHub!

Stay Informed

Sign up for the latest blogs, events, and insights.

We deliver solutions that accelerate the value of Azure.
Ready to experience the full power of Microsoft Azure?

Atmosera is thrilled to announce that we have been named GitHub AI Partner of the Year.

X