Verify
Verify sends one-time codes by SMS or email and checks what the person types. MsGine generates the code, sends it, expires it and limits the attempts, so your app never stores a code.
Send a code and check it
const verification = await msgine.verify.start({ to: '+256701234567', channel: 'sms', appName: 'Acme' });
const result = await msgine.verify.check(verification.id, codeTheUserTyped);
if (result.valid) signIn();verification = msgine.verify.start(to="+256701234567", channel="sms", app_name="Acme")
result = msgine.verify.check(verification["id"], code_the_user_typed)
if result["valid"]:
sign_in()verification, err := client.Verify.Start(ctx, msgine.StartVerificationParams{
To: "+256701234567",
Channel: "sms",
AppName: "Acme",
})
result, err := client.Verify.Check(ctx, verification.ID, codeTheUserTyped)
if err == nil && result.Valid {
signIn()
}The person receives: 482913 is your Acme verification code. It expires in 10 minutes. Do not share it.
If your app does not keep the verification id, check by recipient instead: verify.checkRecipient(to, code) (Python check_recipient, Go CheckRecipient) checks the latest verification for that number or address.
Options
| Option | Default | |
|---|---|---|
channel | required | sms or email |
appName | required | Your app's name in the message, up to 30 characters |
codeLength | 6 | 4 to 8 digits |
expiresIn | 600 | Seconds the code is valid, 60 to 1800 |
from | MsGine | SMS: your approved sender ID. Email: an address on your verified domain |
androidAppHash | none | Your app's SMS Retriever hash, so Android apps read the code automatically |
Rules
- Five attempts. A wrong code returns
valid: falseandattemptsLeft. After the fifth wrong code the verification isfailed. - One code at a time. Starting again for a number that has a pending verification sends the same code again instead of a new one.
resenddoes the same; each verification can be sent three times, at least 30 seconds apart. - Accepted once. After approval, checking again returns
verification_closed. - Limits against abuse. At most 5 codes per number every 10 minutes, and SMS codes go to Ugandan numbers. A request over a limit returns
verify_rate_limitedwith aRetry-Afterheader. - The code stays private. It never appears in API responses, webhooks or your message history, where it is shown as
******.
Statuses
| Status | Meaning |
|---|---|
pending | Sent, waiting for the right code |
approved | The right code was entered |
failed | Five wrong codes |
expired | The time ran out |
canceled | You cancelled it with verify.cancel |
Subscribe a webhook to verification.approved or verification.failed to react on your server.
Price
Each code sent is charged at its channel's price (SMS UGX 30, email from your bundle), plus UGX 20 when a code is approved. Above 100,000 approved verifications in a month the fee is UGX 10. A typical SMS verification costs UGX 50.
Testing
Sandbox keys send nothing and charge nothing, and accept a code of zeros (000000 for six digits), so you can test your sign-in flow end to end.