Two-factor authentication (2FA) can play a key role in securing your applications against password data breaches. Authentication with a one-time password (OTP) delivered to your users over SMS is an effective approach to implementing two-factor authentication. Plivo’s premium direct routes guarantee the highest possible delivery rates and the shortest possible delivery times for your 2FA SMS messages. This guide shows how to set up SMS-based two-factor authentication using either or traditional API development. PHLO lets you create and deploy workflows from an intuitive graphical canvas in few clicks.Documentation Index
Fetch the complete documentation index at: https://plivo.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
- Using API
Here’s how to implement 2FA using Plivo APIs.
Build and run the application from Visual Studio.
Set up ngrok to expose your local server to the internet.You should be able to see the application in action at https://<ngrok_identifier>.ngrok.io/.The finished application should look like this.
Prerequisites
To get started, you need a Plivo account — sign up with your work email address if you don’t have one already. If this is your first time using Plivo APIs, follow our instructions to set up a .NET development environment.Set up the demo application locally
- Clone the 2FA demo repository from GitHub.
- Change your working directory to 2fa-dotnet-demo.
- Open the 2fa folder in Visual Studio.
-
Edit appsettings.json. Replace the auth placeholders with your authentication credentials from the Plivo console. Replace the phone number placeholder with an actual phone number in E.164 format (for example, +12025551234). Replace the PHLO ID with
null.

A review of the code
Let‘s walk through what the code does.Step 1: Generate the OTP
Use the Time-Based OTP algorithm to generate a random six-digit one-time password (OTP).Step 2: Send an SMS message with the OTP
Send an SMS message with the OTP to the user’s registered mobile number using Plivo’s Send Message API.Failover: Make a phone call with the OTP
If the SMS message doesn’t reach the mobile device, the user can request a voice OTP.Step 3: Verify the OTP
Verify the OTP the user entered on their handset.Test
To test the application, start the Redis server.