C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Creating Captcha Page in ASP.Net


Posted Date: 04 Aug 2008    Resource Type: Code Snippets    Category: ASP.NET WebForms

Posted By: Madhavan       Member Level: Gold
Rating:     Points: 7



This code sample tells you how to use captcha images in your ASP.NET web applications.

The following are instructions on how to use the code:
1. Open a new webform(aspx).
2. Write the following captcha code.
3. Call this page in a image control in the Main Page(to display captcha image).

Captcha Code sample is given below:


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;

///
/// Captcha Page.
///

public partial class CaptchaPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
System.Drawing.Bitmap objBmp = new System.Drawing.Bitmap(90, 25);
System.Drawing.Graphics objGraphics = System.Drawing.Graphics.FromImage(objBmp);
objGraphics.Clear(System.Drawing.Color.Green);
objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

System.Drawing.Font objFont = new System.Drawing.Font("Acoustic Light", 11, System.Drawing.FontStyle.Bold);
string strRandom = "";
string[] strArray = new string[36];

strArray = new string[] { "a", "b", "c" , "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q",
"r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

Random autoRand = new Random();
int x;

for (x = 0; x < 6; x++)
{
int i = Convert.ToInt32(autoRand.Next(0, 36));
strRandom += strArray[i].ToString();
}

Session.Add("strRandom", strRandom);
objGraphics.DrawString(strRandom, objFont, System.Drawing.Brushes.White, 3, 3);

Response.ContentType = "image/GIF";
objBmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);

objFont.Dispose();
objGraphics.Dispose();
objBmp.Dispose();

}
}




Responses

Author: vTechIndia    06 Aug 2008Member Level: Bronze   Points : 1

Hi

I read your programme, its nice , i keep getting projects
on captcha can you work on that, can u break all captcha images.

Regards

vijay
09393290361


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Use ASP.NET for Catpcha Images  .  Include captcha images using ASP.NET  .  Include captcha images in your web page  .  Include captcha images  .  Captcha Page  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: A Simple Video Player Control - Uses
Previous Resource: Captcha Images
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

email fax service

Contact Us    Privacy Policy    Terms Of Use