CodeProjectDownload

Sharing knowledge is Art of giving

CodeProjectDownload.com is a Free portal to share Projects in Different languages. you can also send your code or request to being an author to admin.

Like Us On Facebook

To You can like Us on Facebook and share with your friends Facebook »

Member Login

Lost your password?

Not a member yet? Sign Up!

Menu

Related links

Suggetion

captcha code Asp .net

 captcha code Asp .net

Have you looked at our contact us page in many sites define captcha code ? It uses a CAPTCHA,which is an acronym for “Completely Automated Public Turing test to tell Computers and Humans Apart”.The test requires that a person filling out a form on the screen reads some obscured text in an image onthe screen, and types the text correctly. They are designed to make sure that only a human,not an automated computer process intent on malicious purposes, is completing the form,based on the premise that a computer program should not be able to interpret the text displayed on thescreen. You may have been asked to use CAPTCHAs before, when signing up for email accounts social networks and some other online services. Using captcha you identify your system user is human.I geve, here captcha code in asp.net in this you requere to add latest jquery file (you download it from http://jquery.com/)andadd one Image folder name is “numbers” you add images of number image “0.gif” to “9.gif”.you just coppy and past under given code in your asp page.

 

captcha code Asp .net

aspx file code

<%@ Page Language=”C#” AutoEventWireup=”true” CodeBehind=”Default.aspx.cs” Inherits=”ASPNETcaptcha._Default” %>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” >

<head id=”Head1? runat=”server”>

<title>ASP.NET c# captcha Captcha</title>

</head>

<body>

<form id=”form1” runat=”server“>

<div>

<script language=”javascript” src=”jquery-1.2.6.js” type=”text/javascript”></script>

<script type=”text/javascript” language=”javascript”>

$(function() {

$(“#btnSubmit“).click(function() {

if ($(‘#captcharesult‘).val() != $(‘#txtCaptcha‘).val())

{ alert(‘Hint: The solution is ‘ + $(‘#captcharesult’).val() + ‘ :) ’); return false; }

});

})

</script>

Something1: <asp:TextBox ID=”TextBox1” runat=”server“></asp:TextBox><br />

Something2: <asp:TextBox ID=”TextBox2” runat=”server“></asp:TextBox><br />

Something3: <asp:TextBox ID=”TextBox3” runat=”server“></asp:TextBox><br /><br />

<div id=”captcha“>

<input type=”hidden” id=”captcharesult” value=”<%=captcharesult%>” />

<asp:Literal ID=”litCaptcha” runat=”server”/><asp:TextBox ID=”txtCaptcha” runat=”server” Width=”40px”/><br />

<asp:Button ID=”btnSubmit” runat=”server” Text=”Submit Form” Height=”40px” OnClick=”btnSubmit_Click” Width=”144px” />

<asp:Label ID=”lblOK” runat=”server” Text=”Label”></asp:Label>

</div>

</div>

</form>

</body>

</html>

aspx.cs file code

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

namespace ASPNETcaptcha

{

public partial class _Default : System.Web.UI.Page

{

protected int captcharesult;

protected void Page_Load(object sender, EventArgs e)

{

Random rnd = new Random(DateTime.Now.Millisecond + DateTime.Now.Second);

int val1 = rnd.Next(0, 9);

int val2 = rnd.Next(0, 9);

litCaptcha.Text = “Are you human?&nbsp;&nbsp;” + img(val1) + ” + “ + img(val2) + ” = “;

captcharesult = val1 + val2;

}

private string img(int digit)

{

return “<img src=”numbers/” + digit.ToString() + “.gif” height=”15px” alt=”number” + digit.ToString() + “”/>”;

}

protected void btnSubmit_Click(object sender, EventArgs e)

{

lblOK.Text = “Form was submitted, captcha ok!”;

}

}

}