Code length, validity and attempts: choosing length, expires_in and max_attempts

WhatsApp & APIs·· 16 views· 3 min read

The short answer: three fields decide how each code behaves: length (4 to 8 digits, 6 by default), expires_in (1 to 60 minutes, 5 by default) and max_attempts (1 to 10 wrong attempts, 5 by default). Send none of them and the defaults apply, which suit most cases. Change them when the use calls for it.

The three fields

Field What it controls Values Default
length How many digits the code has 4 to 8 6
expires_in The minutes the code stays valid 1 to 60 5
max_attempts Wrong attempts before the code fails 1 to 10 5

Length: the guesser's arithmetic

With 6 digits there are a million possible codes. With 5 attempts, someone typing numbers at random gets it right, on average, 5 times in every million codes. With 4 digits there are only ten thousand codes, and the same 5 attempts give 5 in every ten thousand: a hundred times easier. That is why 6 is the default: easy to type, hard to guess. Use 8 when the transaction is worth a lot; use 4 only when the risk is low and speed matters most.

Validity and attempts for each case

Case length expires_in max_attempts
Confirming the number at sign-up 6 5 to 10 3 to 5
Second login step 6 5 3 to 5
Payment or transfer 6 to 8 5 3
Doorstep delivery 6 up to 60, close to arrival 3 to 5

These suggestions follow the good practice on the Verification SMS page: 6 digits, 5 to 10 minutes validity and 3 to 5 attempts. Validity of hours or days does not exist in this API, and that is a good thing: a code is for now, not for tomorrow.

Attempts do not come back with a resend. POST /v1/sms/otp/{id}/resend sends a new code and the validity starts again, but wrong attempts already used stay used. With max_attempts at 3 and two failed, the resent code has a single attempt. To start from scratch, request a new code with POST /v1/sms/otp.
Put the validity in the text with {minutes}, which we replace with the expires_in value: the customer knows to be quick. See how to write the verification SMS.

Want to choose the length, validity and attempts of each code? See Verification SMS.

See Verification SMS

SEE ALSO

SMS verification API: we generate, send and check the code, and your system keeps only the id

Verification code statuses: pending, verified, expired, failed and cancelled

Resending, cancelling and replacing a verification code: what happens to the old one

Writing the verification SMS: the code placeholder, your Sender ID and staying in one part

Limits against abuse: codes per number per hour and the wait between resends

Sending one-time codes (OTP) by SMS safely: expiry, attempt limits and logs

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from 321,75 MT/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.