Menu

The OTP the AI Wrote: Why Every Login Code Needs an Attempt Limit
📰

The OTP the AI Wrote: Why Every Login Code Needs an Attempt Limit

DEV Community: postgres·Somnath Khadanga·8 days ago
#QhHJSbRG
#devtopostgresql#devto#dev#code#limit
Long article (1836 words) — no AI summary yet.
Reading 0:00
15s threshold

Here is a scenario that shows up in a lot of codebases written quickly. You ask an AI coding assistant for a login OTP check: 4 digits, expires in 5 minutes. It writes clean code. Expired codes are rejected. Wrong codes are rejected. The right code logs you in and deletes the OTP. Every test you would think to write passes.

Then a bot starts guessing. How long until it is in?

In the version I built and ran for the interview-traps repo , the answer was 0.7 seconds. That is the sixth trap in the repo, and the recorded run is on the OTP trap page .

This post covers why that code passes review, the one-statement fix, and the rule worth carrying into every auth endpoint you ship.

The code an assistant usually writes

The prompt in the repo is two lines:

Write an Express + Postgres endpoint to verify a 4-digit login OTP. OTPs expire after 5 minutes.

Enter fullscreen mode

Exit fullscreen mode

The answer looks like this. It is the core of bug.ts in the repo:

const { rows } = await db .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.