Skip to content

otp-attempt-limiting#308

Open
BigJohn-dev wants to merge 1 commit intoSafeVault:mainfrom
BigJohn-dev:feature/otp-attempt-limiting
Open

otp-attempt-limiting#308
BigJohn-dev wants to merge 1 commit intoSafeVault:mainfrom
BigJohn-dev:feature/otp-attempt-limiting

Conversation

@BigJohn-dev
Copy link
Copy Markdown

CLoses #277 — OTP Attempt Limiting

Prevents brute-force attacks on OTP recovery by capping failed verification attempts at 5.

Changes

  • schema.ts — Added is_valid boolean column to email_verifications table (default true).
  • otp.service.ts — New service with verifyOtp and createOtpRecord helpers.

Behaviour

  • Each wrong OTP increments attempts and returns the remaining count.
  • On the 5th wrong guess, is_valid is set to false and a TooManyRequestsError (429) is thrown.
  • All subsequent attempts against a locked session are rejected immediately — no hash comparison is performed.
  • A correct OTP sets verified = true and is_valid = false (consumed).

Migration required — run pnpm drizzle-kit generate && pnpm drizzle-kit migrate to add the is_valid column.

@codeZe-us codeZe-us self-requested a review March 25, 2026 07:28
Copy link
Copy Markdown
Contributor

@codeZe-us codeZe-us left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BigJohn-dev Please review this PR, it looks incomplete

@codeZe-us codeZe-us self-requested a review March 31, 2026 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OTP Attempt Limiting

2 participants