Subscribe Our Email Newsletter using Captcha

A Captcha is a program that protects website against bots by generating tests that humans can pass but current computer programs cannot. For Example : Human can read distorted text as given in example but current computer programs cannot.
The " MSCaptcha.dll" file provides a user control for randomly generating Captcha images.

Source Code For Captcha Control
<%@ Register Assembly="MSCaptcha" Namespace="MSCaptcha" TagPrefix="cap" %>
<cap:CaptchaControl ID="captcha1" runat="server" CaptchaLength="5" CaptchaHeight="50" CaptchaWidth="200" CaptchaLineNoise="None" CaptchaMinTimeout="3" CaptchaMaxTimeout="240" ForeColor="Blue" BackColor="Yellow" CaptchaChars="ABCDEFGHIJKLMNOPQRSTUVWX123456789" Height="46px" Width="200px" />

Webconfig File Setting in <system.web>
<authentication mode="Windows"/>

Webconfig File Setting
<add name="captcha1" verb="GET" path="CaptchaImage.axd" type="MSCaptcha.CaptchaImageHandler, MSCaptcha" />

Important Namespaces Used
using System.Data;
using System.Data.SqlClient;

Subscribe Button Click Event Coding
if (captcha1.UserValidated)
      String query = "insert into emaildetail(emailaddress) values('" + TextBox1.Text + "')";
      String mycon = "Data Source=sk-pc; Initial Catalog=NewsletterDatabase; Integrated Security=true";
      SqlConnection con = new SqlConnection(mycon);
      SqlCommand cmd = new SqlCommand();
      cmd.CommandText = query;
      cmd.Connection = con;
      Label3.Text = "Thanks For Subscribing Our Email Newsletter - Keep Visit Website Also";
      TextBox1.Text = "";
      TextBox2.Text = "";
      Label4.Text = "Incorrect Captcha Text - Re-enter Carefully";

0 Comment's

Comment Form