Skip to main content
Version: 1.0

2.1.1.1.4 OTP Method

Overview

The OTP Verification process allows users to verify their phone numbers by receiving a one-time password (OTP) via SMS, and then entering the OTP in your app to complete the verification.

Get started

Verifying Phone Numbers with OTP

Use verifyPhoneNumberWithOtp to send the OTP to the user's phone number with these parameters:

  • phoneNumber: The user's phone number (including country code).
  • verificationKey: Unique key provided by your backend to ensure verification integrity.
kotlin or java
VerifySpeed.verifyPhoneNumberWithOtp(
"PHONE_NUMBER" // e.g., '+1234567890',
"YOUR_VERIFICATON_KEY",
)
warning

This dependency does not include phone number validation. Since validation occurs server-side, it's best to handle initial validation on your end to reduce user wait times. Use a library like libphonenumber for efficient phone number validation.

Validating OTP

After the user receives the OTP, call validateOTP with these parameters:

  • otpCode: The OTP received from the user.
  • verificationKey: Unique key provided by your backend to ensure verification integrity.
  • callBackListener: Callback interface to handle success and failure cases:
    • onSuccess: Triggered on successful verification, returning a token to retrieve the user's phone number.
    • onFail: Triggered if verification fails, providing error details including type and message.
kotlin
VerifySpeed.validateOTP(
"OTP_CODE", // OTP received from the user
"YOUR_VERIFICATON_KEY", // unique key provided by your backend
object : VerifySpeedListener { // callback listener for success and failure cases
override fun onSuccess(token: String) {
Log.d("VerifySpeed", "Token: $token")
}
override fun onFail(error: VerifySpeedError) {
Log.d("VerifySpeed", "Error: ${error.message}")
}
}
)

Example

For complete implementation examples, see:

Jetpack Compose:

Android Views:

tip

When implementing OTP Verification, look for code comments with the keyword TIP in the example code for guidance on implementation details.

tip

When testing, you'll need to integrate with your backend using these recommended request/response structures (which you can modify as needed).