Short answer: A stateful SMS OTP login backend can send a code and verify it against an auditable challenge record. For healthtech password recovery, that record supports evidence of expiry, failed guesses, cooldowns, and single use. Prefer this design when those decisions must be inspected together. A five-minute expiry is an illustrative application policy here. It isn't a compliance certification. Stateless codes fit a narrower case: expiry validation where the application does not need immediate revocation or a shared record of consumption. Once those requirements arrive, a shared record becomes part of the design anyway.
A patient requests a password reset. The backend sends a code. A delivery callback arrives. Can the team now demonstrate that the code was accepted once, within its lifetime, after fewer than the permitted failed attempts? That is the useful question. A delivery receipt alone cannot answer it.
The same send-code, verify-code, rate-limit, and retry mechanics apply to an SMS login protecting airline disruption alerts. Here the concrete job is medical-account recovery, and the comparison turns on compliance evidence. Keep recovery messages free of medical details. The example identifiers below are synthetic.
How should an SMS OTP login backend send and verify a recovery code?
Before: request → send → delivered.
After: request → policy decision → challenge stored → delivery attempted → verification decision → challenge consumed → limited reset authorization.
See the difference? The second sequence gives the application somewhere to record its security decisions. Delivery stays a separate observation. Under the NIST authenticator guidance, a short authentication secret needs rate limiting, an out-of-band secret must be accepted only once during its validity period, and use of the public telephone network is restricted. Those controls make SMS a constrained recovery option; they do not establish that an entire medical application meets its legal obligations. Account recovery also needs its own risk assessment.
The engineering recommendation is specific: retain challenge state when an evidence review must distinguish an expired code from a consumed one, or demonstrate that two workers could not both accept it. A signature can establish that a payload has not been altered. It does not, by itself, remember a previous acceptance. Adding a consumed-token registry can solve that problem, but it introduces the state this comparison is about.
Keep evidence bounded.
| Design | Evidence boundary | Operational trade-off |
|---|---|---|
| Stateful challenge | Expiry, attempts, and consumption share a record | Requires atomic updates in shared storage |
| Stateless signed code | Signature and expiry can be checked without a challenge lookup | Single use and revocation need additional state |
Use a random challenge identifier in restricted audit events. Record decisions such as cooldown rejected, verification denied, verification accepted, and reset completed. Do not log the code, its digest, the phone number, or the reset authorization. Even an opaque identifier becomes sensitive when it can be joined to an account. Define access and retention separately from the five-minute secret lifetime; no source here establishes a universal retention duration for healthtech recovery records.
A small backend example makes the boundary visible
This TypeScript example runs in a single Node.js process. It demonstrates the application policy, not a deployable messaging service: five-minute challenges, a 30-second resend cooldown, five wrong guesses per challenge, and three sends per 15-minute account window. These numbers are example choices. The NIST guidance supplies the requirements for effective rate limiting and limited validity, not this exact policy.
The account key must come from trusted account resolution. Never treat a caller-supplied phone number as authority to reset an arbitrary account. Use the registered destination after the surrounding recovery policy permits it.
import { createHmac, randomInt, randomUUID, timingSafeEqual } from 'node:crypto'; type Challenge = { id: string; digest: Buffer; expiresAt: number; sentAt: number; wrong: number; used: boolean; }; type Account = { sends: number[]; challenge?: Challenge }; type Delivery = { accountKey: string; challengeId: string; code: string }; export function recoveryDemo(key: Buffer) { if (key.length < 32) throw new Error('Use a random server secret'); const accounts = new Map<string, Account>(); const digest = (accountKey: string, id: string, code: string) => createHmac('sha256', key) .update(JSON.stringify([accountKey, id, code])).digest(); function request(accountKey: string): Delivery | undefined { const now = Date.now(); const account = accounts.get(accountKey) ?? { sends: [] }; account.sends = account.sends.filter(t => now - t < 900_000); accounts.set(accountKey, account); const old = account.challenge; if (account.sends.length >= 3) return undefined; if (old && now - old.sentAt < 30_000) return undefined; if (old && old.wrong >= 5 && now < old.expiresAt) return undefined; const id = randomUUID(); const code = randomInt(0, 1_000_000).toString().padStart(6, '0'); account.challenge = { id, digest: digest(accountKey, id, code), expiresAt: now + 300_000, sentAt: now, wrong: 0, used: false }; account.sends.push(now); return { accountKey, challengeId: id, code }; } function verify(accountKey: string, id: string, code: string): boolean { const challenge = accounts.get(accountKey)?.challenge; if (!challenge || challenge.id !== id || challenge.used || Date.now() >= challenge.expiresAt || challenge.wrong >= 5) { return false; } if (!/^\d{6}$/.test(code) || !timingSafeEqual(challenge.digest, digest(accountKey, id, code))) { challenge.wrong++; return false; } challenge.used = true; return true; } return { request, verify }; } The returned delivery command goes to an adapter that sends the code to the registered destination. Keep it out of logs. The example deliberately has no public HTTP handler: mapping internal outcomes to a generic external response, resolving the account safely, and issuing a limited reset authorization require the surrounding application. A true result permits only the next recovery step. It must not silently become a general login session.
Notice the resend behavior. An allowed request replaces the previous challenge, so an older message can arrive with a code that no longer verifies. That is a deliberate trade-off: simpler evidence about which challenge is active, at the cost of a possible confusing message order. The UI should tell the user to use the most recently requested code. A transport retry is different. It should retry the same delivery command within its remaining lifetime, rather than call request again and rotate the challenge.
There is a sharper limit here: memory is not a shared database. These functions perform their state changes synchronously, without an await inside a decision, which makes the example useful within one process. A restart loses its records. Two independent processes would have independent counters. For deployment, move the checks and updates into transactions in shared storage, use a conditional consume operation, and retain account-level abuse counters independently of challenge replacement. Add network and destination controls so rotating account identifiers cannot evade the overall send budget.
That storage costs work. It also makes the evidence meaningful.
Observe decisions, then test the transitions
A useful audit event answers a small question: which policy decision happened, for which opaque challenge, and when? Keep operational metrics less specific. Count allowed and rejected requests, failed verifications, expired attempts, accepted verifications, and delivery attempts by outcome. Do not use account or challenge identifiers as metric labels. Put restricted correlation details in the audit stream instead, where access and retention can be controlled.
For a concrete review, follow one synthetic challenge through request acceptance, delivery submission, verification acceptance, and reset completion. These are different events. A rise in accepted sends with no successful verifications calls for investigation; it does not prove a carrier problem. Users may abandon the flow, messages may arrive late, or a deployed verification policy may reject their attempts. Compare the event sequence before choosing an alert threshold. No universal threshold follows from the sources here.
Test the boundary moments. At exactly five minutes, verification must fail. A second verification after a successful consume must fail too. Exercise the fifth incorrect guess, a resend inside 30 seconds, a delayed old message, and two concurrent correct submissions against the production store. For that last test, expect one consumption and one denial. Also test the point where a delivery worker loses its acknowledgement: an ambiguous transport outcome must not create a fresh code or erase the application's rate-limit history.
Deployment belongs in that review. Version the recovery policy in evidence events, ensure all workers agree on expiry semantics, and test a rollout with old and new workers active together. Make an explicit decision about delivery commands that outlive their challenge. Dropping an expired command is easier to explain than sending a message the verifier can no longer accept.
Would stateless codes or email remove this work?
The first objection is reasonable: a signed code avoids a challenge lookup. If the actual requirement is only to validate an expiration time, that can be a useful simplification. For this recovery job, though, single use and immediate invalidation are part of the decision. A shared consumption registry, attempt counter, and revocation mechanism bring storage back. Choose the stateful design when those controls need to be inspected together. Teams must budget for schema changes, transactional behavior, and support tooling; the benefit is a coherent account of why a verification was accepted.
The second objection is to switch channels and call the evidence problem solved. Email changes delivery and account-control assumptions. It does not remove expiry, single use, or throttling. RFC 7489 describes DMARC alignment and policy for email authentication; it does not certify that a reset was redeemed by the intended person, and it cannot serve as an SMS delivery control. If recovery uses email, treat domain authentication as one layer alongside the application's challenge lifecycle.
Choose the channel through a recovery risk assessment, then keep the evidence chain intact. For a short-lived healthtech reset, the decisive capability is an inspectable, atomic transition from outstanding challenge to consumed challenge. That is why stateful challenges win this comparison.
References
The NIST reference supports the discussion of authenticator validity, one-time acceptance, throttling, and restrictions on telephone-based out-of-band authentication. The email reference supports the narrower explanation of DMARC. The time windows, counters, event design, and TypeScript implementation above are illustrative application choices.
Further reading
- NIST SP 800-63B, Digital Identity Guidelines: Authentication and Lifecycle Management: https://pages.nist.gov/800-63-3/sp800-63b.html
- RFC 7489, Domain-based Message Authentication, Reporting, and Conformance (DMARC): https://datatracker.ietf.org/doc/html/rfc7489

