Sunday, 1 April 2018

Send OTP ( One Time Password ) SMS to Verify user Mobile Number in Asp.Net C#

Important Namespaces Used
--------------------------

using System.Net;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Specialized;


---------------------------


(Send Otp) Button Click Event Coding
--------------------------------------

Panel1.Visible = false;
        Panel2.Visible = true;
        Random random = new Random();
        int value = random.Next(1001, 9999);
        string destinationaddr = "91" + TextBox1.Text;
        string message = "Your OTP Number is " + value + " ( Sent By : Coding Logic and Syntax )";
        //Label3.Text = message;
        String message1 = HttpUtility.UrlEncode(message);

        using (var wb = new WebClient())
        {
            byte[] response = wb.UploadValues("https://api.textlocal.in/send/", new NameValueCollection()
                {
                {"apikey" , "FammnpFW0Ks-gRKkiQvnke2nG940NkDbbl4jUV4elK"},
                {"numbers" , destinationaddr},
                {"message" , message1},
                {"sender" , "TXTLCL"}
                });
            string result = System.Text.Encoding.UTF8.GetString(response);
            Session["otp"] = value;


        }


--------------------------------------


( Verify ) Button Click Event Coding
--------------------------------------

 if(TextBox2.Text==Session["otp"].ToString())
        {
            Panel2.Visible = false;
            Label3.Text = "Your Mobile Number Has Been Verified Successfully - Thanks";
        }
        else
        {
            Label3.Text = "OTP Number is Not Correct : Your Mobile Number not Verified";
            Panel2.Visible = true;
        }


----------------------------------------

7 comments:

  1. this is not working .I cannot send MSG

    API key -"uxCstHkdalY-OfYbCOrFXl0F4nqPmGboWDC7sUiOuJ"

    I need your help .



    below is my code
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    using System.Net;
    using System.Data;
    using System.Data.SqlClient;
    using System.Collections.Specialized;

    namespace OTP_generation
    {
    public partial class Mobile_Verification : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {
    Panel1.Visible = false;
    Panel2.Visible = true;
    try
    {

    Random random = new Random();
    int value = random.Next(1001, 9999);
    string destinationaddr = "91" + TextBoxmob.Text;
    string message = "Your OTP Number is" + value + "(Sent by Payal Morekar----Testing Testing)";
    string message1 = HttpUtility.UrlEncode(message);


    using (var wb = new WebClient())
    {
    byte[] response = wb.UploadValues("https://api.textlocal.in/send/", new NameValueCollection()
    {
    {"apikey" , "uxCstHkdalY-OfYbCOrFXl0F4nqPmGboWDC7sUiOuJ"},
    {"numbers" , destinationaddr},
    {"message" , message1},
    {"sender" , "TXTLCL"}
    });
    string result = System.Text.Encoding.UTF8.GetString(response);
    Session["otp"] = value;

    }
    }
    catch (Exception es)
    {
    Response.Write(es.ToString());
    }
    }

    protected void Buttonverotp_Click(object sender, EventArgs e)
    {
    if (TextBoxotp.Text == Session["otp"].ToString())
    {
    Panel2.Visible = false;
    Response.Write("Your Mobile Number Has Been Verified Successfully - Thanks");
    }
    else
    {
    Response.Write("OTP Number is Not Correct : Your Mobile Number not Verified");
    Panel2.Visible = true;
    }

    }




    }
    }

    ReplyDelete
  2. OTP message is not showing the message

    ReplyDelete
  3. Not Working Properly
    i Need Your Help



    using System;
    using System.Collections.Generic;
    using System.Net;
    using System.Collections.Specialized;
    using System.IO;
    using System.Text;


    using System.Web;
    using System.Net;
    using System.Data;
    using System.Data.SqlClient;
    using System.Collections.Specialized;

    public partial class User_OTP : System.Web.UI.Page
    {
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
    Panel1.Visible = false;
    Panel2.Visible = true;
    Random random = new Random();
    int value = random.Next(1001, 9999);
    string destinationaddr = "91" + TextBox1.Text;
    string message = "Your OTP Number is " + value + " ( Sent By : Coding Logic and Syntax )";
    //Label3.Text = message;
    String message1 = HttpUtility.UrlEncode(message);

    using (var wb = new WebClient())
    {
    byte[] response = wb.UploadValues("https://api.textlocal.in/send/", new NameValueCollection()
    {
    {"apikey" , "Lqn5n6ovuDM-tfn3l6kNLpHHaMA2X8Usl0brJORqyU"},
    {"numbers" , destinationaddr},
    {"message" , message1},
    {"sender" , "TXTLCL"}
    });
    string result = System.Text.Encoding.UTF8.GetString(response);
    Session["otp"] = value;
    }

    }
    protected void Button2_Click(object sender, EventArgs e)
    {
    if (TextBox2.Text == Session["otp"].ToString())
    {
    Panel2.Visible = false;
    Response.Write("Your Mobile Number Has Been Verified Successfully - Thanks");
    }
    else
    {
    Response.Write("OTP Number is Not Correct : Your Mobile Number not Verified");
    Panel2.Visible = true;
    }


    }

    }

    ReplyDelete
  4. verified mobile number is not receiving OTP

    ReplyDelete
  5. That is really nice to hear. thank you for the update and good luck. Ben Luker Modern Behaviour

    ReplyDelete

Banking System Project

//*************************************************************** //                   HEADER FILE USED IN PROJECT //********************...