First things first! Looking at the problem defined above, an
ASP.NET developer would guess that the implementation doesn’t have a very
complex structure as long as the text messaging part is handled, and that is
right. One of the biggest requirements of 2-step verification is a secure and
reliable service to send your text messages from. This can be achieved by
several services, but these days Twilio has become the
de facto standard for phone communication for programmers. A cloud-based
reliable solution with high security and simplified API wouldn’t leave doubts
for you to use it as the solution unless you’re living outside the United
States and Canada and may need to use your local service.
After referencing the Twilio API on Nuget (or manually), you can
implement a very simple class to send a text message from your Twilio number to
a destination number (Listing 1).
Listing 1: Text message communication
using Twilio;
namespace AspNetPhoneVerificationSample.Components
{
public static class Messenger
{
public static void SendTextMessage(string number, string message)
{
TwilioRestClient twilioClient =
new TwilioRestClient("acccountSid", "authToken");
twilioClient.SendSmsMessage("+12065696562", number, message);
}
}
}