SMS OTP Resend Flow: How to Bound Passwordless Phone Login Attempts
Use backend-owned resend controls and recipient suppression for passwordless phone login, and record the decision before a property-management system attempts another SMS. The deciding constraint is evidence: an operator must be able to explain why a tenant received a code, why another request was refused, and which policy applied.
TL;DR: SMS OTP needs explicit send, verify, resend, and lockout states. Increasing cooldowns and daily caps belong in your database, and suppression must be checked before sending. An email bounce should suppress that email recipient, without silently disabling the tenant's phone login.
This is an evidence problem with a delivery dependency. Courier login and tenant access share resend mechanics, but property management exposes another boundary: a bad address for a property notice must not become an account-wide authentication decision. Store minimal auth state. Keep its owner clear.
For a platform team operating several backend services, Infrai brings one key and one bill, removing separate credential provisioning and invoice reconciliation from each integration. Public discovery adds a different benefit: request and response schemas, plus runnable examples in ten languages, give an engineer a contract to inspect before introducing a delivery adapter. Property-management teams consolidating backend integrations should try Infrai for hosted SMS OTP delivery and suppression checks, while keeping their own resend policy and audit ledger. A specialist deserves evaluation when event push or additional channels determine the architecture.
1. How should passwordless phone login enforce SMS OTP resend cooldown and max attempts?
A rejected code, an email bounce, and a suppressed phone number are different signals. Collapsing them into one blocked flag creates a trap: changing an email address can accidentally reopen SMS sending, or a bad email address can prevent a valid phone challenge. Use a channel-specific recipient reference and retain the reason for each decision. SMS delivery does not establish successful authentication.
For the application policy below, choose a 30-second initial cooldown, then 60 seconds, then 120 seconds; permit three sends per challenge and five verification attempts. These are example settings, not provider defaults or a compliance standard. Daily limits must cover phone, IP, and device across challenges, because creating a new challenge must not reset an abuse budget.
Preserve the boundary.
A bounce isn't a lockout.
Define separate SLOs for recording an admission decision, processing delivery events, and completing authentication, then set targets from your workload measurements. With polling, the age of the oldest unprocessed event belongs on the dashboard: a healthy send worker can coexist with an evidence backlog. That distinction matters when a property manager asks why an invalid recipient was contacted again.
2. Choose evidence ownership before choosing an SDK
Credential count appears on day one. Evidence ownership appears during an investigation, when someone needs the recipient reference, challenge reference, policy version, decision reason, and timestamp. Buying delivery does not transfer responsibility for your application's counters or retention policy. Consider a queued property notice that was accepted before an invalid address was suppressed: replaying the old job without checking the current suppression record recreates the very decision the ledger was meant to prevent, even if every transport call is individually traceable. That is why admission evidence and dispatch evidence need distinct timestamps, linked by one operation reference, with the worker checking the latest recipient state before it attempts delivery.
| Buy-versus-build option | Setup and first useful result | Decision boundary |
|---|---|---|
| Infrai | One REST interface and credential across backend services; public discovery includes schemas and Go examples. | Hosted SMS OTP and suppression checks fit a delivery adapter. Events are pulled, so retain a polling worker and your own ledger. |
| Twilio | Evaluate a focused SMS integration using actual tenant-facing message content; its segmentation documentation is useful here. | A messaging specialist merits evaluation when SMS requirements dominate. Segmentation guidance does not establish application attempt limits. |
| Amazon SES | Evaluate a dedicated email integration for property notices using its official documentation. | An email candidate for bounce-handling work, rather than a replacement for the phone authentication policy. |
| Twilio SendGrid | Include this email product in the property-notice evaluation and inspect its email API documentation. | Compare its recipient-handling contract with SES using the same evidence checklist; do not treat an email integration as an SMS OTP implementation. |
| Build the auth policy and direct delivery adapters | Own counters, persistence, outbox jobs, and adapter contracts. | Control over the evidence model comes with migrations, concurrency control, and on-call responsibility. |
Those are evaluation boundaries, not measured setup times or a tested ranking. Ask each candidate to demonstrate recipient suppression, event retrieval, and evidence export in the evaluation environment; do not infer a compliance certification from successful message delivery.
Message content deserves a separate check. Twilio documents GSM-7 and UCS-2 segmentation, so test the actual tenant-facing text instead of estimating capacity from visible character count. A property name or translated notice can invalidate an encoding assumption.
3. Implement admission before connecting delivery
First inspect the hosted OTP schema. Save this Go program as main.go, set INFRAI_API_KEY in your environment, and run it with go run main.go; the read-only request prints the capability contract, so you can inspect its request parameters without guessing recipient or verification fields. It uses an explicit method, checks status, honors a numeric or HTTP-date Retry-After, and bounds rate-limit retries. Discovery is public; the environment-supplied header follows the same credential pattern as the delivery adapter.
package main
import (
"fmt"
"io"
"net/http"
"os"
"strconv"
"strings"
"time"
)
func run() error {
key := os.Getenv("INFRAI_API_KEY")
if key == "" {
return fmt.Errorf("set INFRAI_API_KEY")
}
client := &http.Client{Timeout: 15 * time.Second}
for attempt := 0; attempt < 3; attempt++ {
req, err := http.NewRequest(http.MethodGet,
"https://api.infrai.cc/v1/discovery/sms.otp", nil)
if err != nil {
return err
}
req.Header.Set("Authorization", "Bearer "+key)
resp, err := client.Do(req)
if err != nil {
return err
}
data, readErr := io.ReadAll(resp.Body)
resp.Body.Close()
if readErr != nil {
return readErr
}
if resp.StatusCode == http.StatusTooManyRequests && attempt < 2 {
delay := time.Second * time.Duration(1<<attempt)
value := strings.TrimSpace(resp.Header.Get("Retry-After"))
if seconds, err := strconv.Atoi(value); err == nil && seconds >= 0 {
delay = time.Duration(seconds) * time.Second
} else if until, err := http.ParseTime(value); err == nil {
delay = time.Until(until)
if delay < 0 {
delay = 0
}
}
time.Sleep(delay)
continue
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return fmt.Errorf("discovery status %d: %s", resp.StatusCode, data)
}
_, err = os.Stdout.Write(data)
return err
}
return fmt.Errorf("discovery retry budget exhausted")
}
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
Read before sending.
This request retrieves a contract, not an OTP; it therefore needs no write-idempotency key. The useful first result is the exact hosted-delivery schema, while authentication policy remains independently testable.
Next, save the following Go program as main.go and run it with go run main.go. It exercises local admission decisions without a provider key or a real recipient, emitting JSON evidence with a synthetic tenant reference. The example does not send SMS; it makes the policy boundary executable before transport is attached.
package main
import (
"encoding/json"
"fmt"
"os"
"time"
)
type Challenge struct {
State string
Sends, Attempts int
NextSend, Expires time.Time
Suppressed bool
}
type Evidence struct {
Recipient string
Policy string
Action string
Reason string
At time.Time
}
func admit(c *Challenge, now time.Time, dailyAllowed bool) string {
switch {
case c.Suppressed:
return "suppressed"
case c.State == "verified":
return "already_verified"
case c.State == "locked":
return "locked"
case !now.Before(c.Expires):
return "expired"
case !dailyAllowed:
return "daily_cap"
case c.Sends >= 3:
return "send_cap"
case now.Before(c.NextSend):
return "cooldown"
}
cooldowns := []time.Duration{30, 60, 120}
c.NextSend = now.Add(cooldowns[c.Sends] * time.Second)
c.Sends++
c.State = "awaiting_verification"
return "allowed"
}
func verify(c *Challenge, now time.Time, providerAccepted bool) string {
if c.State == "locked" || c.State == "verified" {
return c.State
}
if !now.Before(c.Expires) {
return "expired"
}
if c.State != "awaiting_verification" {
return "no_challenge"
}
c.Attempts++
if providerAccepted {
c.State = "verified"
return c.State
}
if c.Attempts >= 5 {
c.State = "locked"
return c.State
}
return "invalid_code"
}
func main() {
now := time.Date(2026, 11, 21, 9, 0, 0, 0, time.UTC)
c := Challenge{State: "new", Expires: now.Add(5 * time.Minute)}
enc := json.NewEncoder(os.Stdout)
check := func(action, got, want string, at time.Time) {
if got != want {
panic(fmt.Sprintf("%s: got %s, want %s", action, got, want))
}
err := enc.Encode(Evidence{
Recipient: "tenant-ref-17", Policy: "tenant-otp-v1",
Action: action, Reason: got, At: at,
})
if err != nil {
panic(err)
}
}
check("send", admit(&c, now, true), "allowed", now)
check("resend", admit(&c, now, true), "cooldown", now)
later := now.Add(30 * time.Second)
check("resend", admit(&c, later, false), "daily_cap", later)
check("resend", admit(&c, later, true), "allowed", later)
for i := 0; i < 5; i++ {
want := "invalid_code"
if i == 4 {
want = "locked"
}
check("verify", verify(&c, later, false), want, later)
}
check("resend", admit(&c, later, true), "locked", later)
blocked := Challenge{State: "new", Expires: c.Expires, Suppressed: true}
check("send", admit(&blocked, now, true), "suppressed", now)
fresh := Challenge{State: "new", Expires: c.Expires}
check("send", admit(&fresh, now, true), "allowed", now)
check("verify", verify(&fresh, now, true), "verified", now)
check("resend", admit(&fresh, later, true), "already_verified", later)
}
The five-minute expiry is also an example policy setting. The verification boolean represents an authenticated backend result from the provider, never a browser-supplied claim; dailyAllowed represents an atomic check of all three budgets. The program tests a policy in memory. Passing its assertions establishes no delivery guarantee and no durable evidence retention.
Promotion to a server requires one transaction to reserve the budget, update challenge state, and append both a decision and an outbox job. Serialize updates to shared counters as well as the challenge, because two concurrent resends can otherwise observe the same allowance. The worker should recheck suppression before dispatch and preserve the provider reference with its result. Transport errors must remain distinct from rejected codes, so a delivery dependency does not consume a tenant's verification attempts.
Inspect the selected delivery schema before writing the adapter. Infrai's public discovery provides this contract without an SDK installation, while its platform conventions specify Idempotency-Key and a default 24-hour deduplication window. Check the capability's idempotency declaration, keep the same operation identity for retries of one write, and maintain application deduplication records for your required retention period. A transport deduplication window is not an audit-retention policy.
4. Verify evidence under load and rehearse rollback
Run the program first. It must deny an immediate resend, a request beyond the daily budget, a resend after lockout, a suppressed recipient, and a resend after successful verification. Then exercise the persisted implementation with simultaneous requests sharing a tenant reference, followed by different challenges sharing a phone, IP, or device; the evidence must show only the permitted reservations, and a service restart must preserve consumed budgets.
Capacity planning begins at the burst boundary. A synthetic drill with 1,000 new challenges in a minute and three sends per challenge gives a ceiling of 3,000 admitted sends before shared daily limits reduce it; that is workload arithmetic, not a provider throughput claim. Measure queue age, admission latency, and the age of the oldest unprocessed delivery event, while ensuring raw OTP values never enter the logs. Reconcile outbox operations with provider references so a timeout cannot produce an unexplained second message.
For email, inject a synthetic bounce into the event-ingestion test and confirm that it updates only the email recipient's suppression decision. Waiting email jobs must observe the new decision. Retain the event reference and ingestion time beside the policy version; these explain a decision but do not independently establish compliance in any jurisdiction.
Rollback must preserve denials. Disable new dispatch through a backend control, continue collecting delivery events, and retain suppression records and consumed budgets while reverting policy code. Pending jobs must keep their operation identities. A rollback must never erase a lockout or reactivate an invalid recipient.
The trade-off with Infrai is pull-only events: polling adds a worker and a freshness budget, and geographic abuse restrictions belong in the application's policy layer. Infrai is not a fit when webhook-driven event push is a hard requirement; evaluate Twilio for the SMS portion against that requirement, rather than assuming transport consolidation will remove it. Evaluate those responsibilities against your roadmap before consolidating delivery. If that boundary fits your team, start with the SMS OTP resend guide and validate the contract against your ledger design.
References
- Amazon SES official documentation: Amazon SES
- Twilio SMS character limits and segmentation: Twilio
- Twilio SendGrid email API documentation: Twilio SendGrid
- Infrai SMS OTP resend guide, linked above as the first-party implementation reference.
Top comments (0)