Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Captcha validation in Asp.net 2.0



Captcha validation in Asp.net 2.0.

Before Entering to topic first we must understand about the validation.Why most of the sites are validating the data's we entered.Like we gave a name with numeric values and special characters like.So these things are really wrong information by mistake wrongly typed.In email id most of the websites how they validate means they see the email id contains '@' followed with some words and having '.' symbol. So we have to give the informations correctly.

Ok, Let us come to the Topic.
most of the web sites having the Captcha validation to their sites.

What is a Captcha code?

Captcha code contains a char and integer values with mixed mode. It is used for validating this code was really typed by the human.

How to create our own Captcha code in Asp.net 2.0

First create an image button in a Asp.net web page and in the imageurl give the capthanew.aspx. like this,

<asp:imagebutton id="ImageButton1" runat="server" width="105px" height="35px" imageurl="~/capthanew.aspx">

<asp:TextBox ID="txtcaptha" runat="server" Width="105px" MaxLength="6" CssClass="txtbx2"></asp:TextBox>

<asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="btnSubmit_Click" />

give a text box to enter the captcha text and also a button.

download the capthanew.aspx file from here Download

save the file in your website folder.

In aspx.cs file go to the btnSubmit_Click event to write the validation to check the user given code and captcha code are same.

if (Page.IsValid && (txtcaptha.Text.ToString() != Session["RandomStr"].ToString()))
{
Response.Write("Captcha code was wrong.");
}

This is the implementation of a captcha code if you want to generate the code dynamically means just give a linkbutton near to the Captcha imagebutton and give the path to capthanew.aspx this will give a dynamic code whenever you reload the page by linkbutton.

Actually how this captcha code works means, we just create a random numbers and characters and create a bitmap image and render these two things. We can give our own color also.

Happy code for Captcha. download the capthanew.aspx file from here Download



This post first appeared on Dotnet, please read the originial post: here

Share the post

Captcha validation in Asp.net 2.0

×

Subscribe to Dotnet

Get updates delivered right to your inbox!

Thank you for your subscription

×