How to Generate and Send OTP SMS For Free using C#.NET?

12 9,546

As you all guyz know that security of user account is the critical problem in these days. So, the developer have to think about how they can secure their user account. This is can done by generating and sending OPT to the user phone number through SMS.

First understand what is OTP?

A One Time Password (OTP) is a unique code/token generated by our application, sent to a user via SMS text and then entered into our application login/signup flow for additional security.

  • People supply a mobile number when they join your service.
  • You generate a unique code and merge it into an SMS text and send to the user.
  • The user types the code into a form on your server and you verify the code matches.
  • You delete the code after a successful login or after a period of time.

One-Time Passwords are only effective for a fixed period of time and become invalid once the user logs in, making them exceptionally useful against spyware such as key logging programs.

One you have built One Time Passwords into your activation/signup flow a One Time Password will be texted every time a login attempt is made.  This flow will dramatically improve account security.

“This tutorial may be very useful for those who want to integrate OTP features in their project which is developed in C#.NET”.

So for this, we have to take the help of SMS gateway to send the OTP to the user Phone Number.

We are going to take help of txtlocal as our SMS gateway. All you have do is go to and there you need to create one account. after creating account. (you need to fill up some of your information and txtlocal will send you a verification email into your email and verify your account [watch the video for detail]).After completing this step, go and from the select language option choose C# and then copy the code and edit as in the following manner or simply copy the following code but you need to provide your own api key when you run this project.

Now write the following piece of code after designing the following form in Visual Studio.


if you have any confusion, you can watch the following video: