Require an auditable challenge lifecycle for a healthcare SMS OTP login API, including its resend cooldown and code verification. The deciding constraint is compliance evidence: a delivery receipt cannot establish that the intended account completed verification. Apply the same policy to a signup verification link.

Short answer: keep issuance, resend cooldown, verification attempts, expiry, and consumption under application control. These are the 5 controls this example records. Send a signup link through a delivery adapter, and apply the same challenge policy if the user enters an SMS code instead. Treat appointment reminders as a separate workflow with separate content and access rules.

For a one-person SaaS, the revenue-per-hour question is how much evidence the application can produce without turning every support request into a database investigation. Outsource the undifferentiated transport. Own the decision that changes an account from pending to verified. Ship weekly, with that decision covered by tests.

How should a healthcare SMS OTP login API verify signup?

Start with a narrow claim: someone presented the secret associated with a pending signup challenge. That observation does not establish legal identity, clinical authority, or permission to read an appointment. A verified phone number also does not prove that the person holding it is the patient named in a record. Keep the signup result scoped to the account and purpose that created it.

The cited NIST authenticator guidance distinguishes authentication mechanisms and treats use of the public telephone network for out-of-band authentication as restricted. It also calls for rate limiting short authentication secrets and accepting a given secret only once during its validity period. Those are useful engineering constraints; they do not certify a healthcare application. Email address confirmation should likewise remain distinct from a claim that email is an acceptable out-of-band authenticator under that guidance.

Evidence needs boundaries. A phone possession check isn't proof of a patient's identity.

For this design, record an opaque challenge identifier, an internal account reference, its purpose, timestamps, the policy version, and the verification outcome. Do not put the SMS code, link token, full destination, or appointment details in those events. An event such as signup verification accepted should be enough to locate the relevant policy and account transition without copying message content into another system. Retention and access rules still need a documented decision from the people responsible for the application's obligations; neither of the references below supplies a universal healthcare retention period.

The constraint that changes the implementation

A resend button looks like a delivery feature. In this build, it is a state transition that must leave evidence. Consider two tabs requesting a message together: if each checks the last-send timestamp before either saves its update, both can pass a cooldown check. A second trap is replacing the challenge on every resend and quietly restoring the attacker's verification budget.

The initial policy below uses a 60-second resend cooldown, a 5-minute challenge lifetime, and 5 failed verification attempts across the pending challenge. These are illustrative application choices, not values prescribed by the cited standards. A resend repeats the existing challenge and does not extend its lifetime or reset its attempt count. Once expired or locked, a new challenge requires a separate issuance decision with an account-level budget. That last boundary matters. A five-attempt counter offers little protection if a caller can request a fresh counter immediately. Apply issuance limits across challenge replacements, with additional network-level controls where appropriate; avoid a permanent account lock that lets a stranger deny access to the real user. Record the reason for a denied request internally while keeping public responses from revealing whether an account exists.

Don't let a new message purchase a fresh guessing budget for an existing account.

For the signup link, the application issues a long random token and stores a digest. For the alternative SMS path, generate the numeric code with a cryptographically secure random generator and protect the stored value with a keyed digest whose key lives outside the challenge database. A short numeric code has a small search space. Merely hashing it does not provide the same resistance to offline guessing as a long random link token.

Delivery comes after the issuance decision. Persist the challenge and a send job together, then let a worker call the transport adapter. That transaction gives an audit trail for accepted requests even when a worker retries later. It does not promise exactly-once external delivery. A duplicate message should point at the same pending challenge, not create an extra opportunity to verify.

The smallest verification core worth shipping

Here is the TypeScript core for a Node.js service. It deliberately defines a storage contract: a production adapter must implement the transaction guarantees in the comments. The function is the verification decision, not a complete server or a substitute for the issuance and delivery worker described above. The secret can be an SMS code or a signup-link token; issuance decides which channel and digest belong to this challenge.

import { createHmac, timingSafeEqual } from "node:crypto"; type Result = "accepted" | "rejected"; type Challenge = { id: string; accountId: string; purpose: "signup"; digest: Buffer; expiresAt: number; failures: number; consumedAt: number | null; }; type Evidence = { challengeId: string; at: number; policy: "signup-v1"; outcome: "accepted" | "invalid" | "closed"; }; interface VerificationStore { // Serialize calls for this ID across all application instances. // Commit challenge updates, account verification, and evidence together. // Roll back all changes if the callback or the commit fails. transaction<T>( id: string, work: (tx: { challenge: Challenge | null; markAccountVerified(accountId: string): void; record(event: Evidence): void; }) => T, ): Promise<T>; } export function digestSecret( key: Buffer, challengeId: string, secret: string, ): Buffer { return createHmac("sha256", key) .update(JSON.stringify([challengeId, secret])) .digest(); } export async function verifySignup( store: VerificationStore, key: Buffer, challengeId: string, secret: string, clock: () => number = Date.now, ): Promise<Result> { return store.transaction(challengeId, (tx): Result => { const now = clock(); const c = tx.challenge; if (!c) return "rejected"; const record = (outcome: Evidence["outcome"]) => tx.record({ challengeId: c.id, at: now, policy: "signup-v1", outcome, }); if (c.purpose !== "signup" || c.consumedAt !== null || now >= c.expiresAt || c.failures >= 5) { record("closed"); return "rejected"; } const candidate = digestSecret(key, c.id, secret); const matches = c.digest.length === candidate.length && timingSafeEqual(c.digest, candidate); if (!matches) { c.failures += 1; record("invalid"); return "rejected"; } c.consumedAt = now; tx.markAccountVerified(c.accountId); record("accepted"); return "accepted"; }); } 

The account comes from stored state, never from an account identifier supplied alongside the code. The purpose is fixed to signup. A reminder access challenge belongs to a different purpose and must not be accepted here. The clock is read inside the transaction, after any wait for serialization, so a request cannot retain an earlier validity decision while waiting on another verifier.

Keep secrets out. The audit record should explain the decision without reproducing the credential.

The HTTP boundary still needs request-size limits, input validation, issuance throttles, and a generic rejection response. Missing challenge IDs need aggregate abuse telemetry rather than unlimited per-request audit rows. Storage errors should fail the request without marking the account verified; retrying must encounter the same persisted state. Digest-key rotation also needs a key identifier on persisted challenges or a deliberate expiration plan. Those are deployment requirements, not capabilities supplied by this function.

A signup link introduces another practical choice. A GET request should display a confirmation page; an explicit confirmation action should submit the token for consumption. Automated message inspection must not silently complete the signup. Keep third-party resources off the token-bearing page, avoid logging its query string, and define how the token leaves browser history. This adds a click, but it makes the acceptance event easier to explain.

Test the evidence before expanding delivery

The useful test is not just that the correct code succeeds. Run two valid submissions concurrently against the actual storage adapter and require one accepted transition. Replay the secret after success. Try it at the exact expiry boundary, after the fifth failed attempt, and after a resend. Verify that a new challenge does not bypass the account-level issuance limit. Then force the evidence write to fail and confirm that the account transition rolls back with it. These checks test the claim the audit trail is supposed to support.

An accepted event without its matching account transition is a failed test, too.

Delivery needs its own exercise: stop the worker after transport submission but before job acknowledgement, then retry the job. The verification result should remain a single account transition even if a message is repeated. Inspect logs and traces during that run for tokens, codes, and destinations. A redacted application log is insufficient if the HTTP access log still captures the full link.

For an email link, domain authentication is a separate piece of evidence. RFC 7489 describes DMARC policy and reporting around aligned authentication results. It does not establish that a person read a message or clicked its link. Keep domain-authentication results, transport events, and successful challenge consumption as distinct observations, so support tooling cannot turn a delivery status into a verified account.

Deploy policy changes with an explicit rule for outstanding challenges. Store the policy version and preserve its meaning until those challenges expire. During a weekly release, changing the meaning of an existing event label creates avoidable review work. Count accepted verifications, expired challenges, denied resends, and exhausted attempt budgets separately; those counters answer different operational questions.

What I would change at scale

I would first move contention and abuse controls into shared storage, keeping the same acceptance transaction and evidence fields. More application processes must not multiply the guessing budget. Partition delivery work independently so a backlog of appointment reminders cannot consume all capacity reserved for signup verification.

The trade-off is more operational machinery: queue ownership, policy migrations, restricted evidence access, and a retention process. Add each piece when its failure mode justifies the maintenance time. For a solo founder, revenue per hour improves when outsourced transport stays replaceable and the small amount of application-owned security logic remains testable.

The release criterion is concrete: produce evidence for why a signup was accepted, demonstrate that concurrent requests cannot consume it twice, and show that resend and replacement cannot erase the attempt budget. Keep that standard as the system grows.

References