Thursday, October 23, 2008

Asp.Net CAPTCHA and Asp.Net AJAX CAPTCHA


I am using a great Asp.Net CAPTCHA by BrainJar in a number of web sites with and without Asp.Net AJAX. It’s a simple and really easy to use Asp.Net CAPTCHA. The actual source code is in C#, but you can use it with both C# and VB.Net by simply wrapping the functionality in a class library.

In Asp.Net forums and in many other user communities I have seen lot of people asking for VB.Net CAPTCHA. So I thought to write a blog post and create some sample implementations. The zip file contains C# CAPTCHA and VB.Net CAPTCHA. I have included the samples for Asp.Net AJAX CAPTCHA also.

You can download the samples and implementation from here

Implementing Asp.Net AJAX CAPTCHA is really simple. Just wrap the main Asp.Net CAPTCHA with Asp.Net AJAX update panel and put a random query string at the end of CAPTCHA image src. The random query string will avoid showing the old CAPTCHA from browser cache.

STEPS TO ADD ASP.NET CAPTCHA IN YOUR WEBSITE
  1. Refer the assembly CaptchaDLL.dll in your project
  2. Copy JpegImage_CS.aspx or JpegImage_VB.aspx (according to the language of choice) to your website.
  3. Open the above file and make changes in Colors and Font if needed. (read the inline comments to know more)
  4. Now user the sample codes from Default.aspx or Ajax.aspx pages. The code is straight forward. You make a session and generate an image with the string in the Session. Now when you submit you have to check the session value and textbox value to see whether the entered CAPTCHA is correct.
DOWNLOAD THE SOURCE AND SAMPLES FROM HERE

If you have any questions please put as a comment.

Tags
Asp.Net CAPTCHA, CAPTCHA, VB.Net CAPTCHA, C# CAPTCHA, ASP CAPTCHA, C sharp captcha, vb captcha, simple captcha, AJAX CAPTCHA, asp.net ajax captcha, captcha without refresh, captcha using ajax, numeric captcha

23 comments:

Unknown said...

Good one,
Thanks

Saqib Vaid

Unknown said...

Excellent..
Is it free to use this CAPTCHA tool in my web site? Or I required some agreement, licensee? Thank you

Anonymous said...

Great. Thanks for your sharing.

Anzer said...

@ST
Its free and there is no licenses needed to use in your projects..

Netcougar said...

Great to see. I have been searching around for one that was UpdatePanel agnostic. Thank you.

Anonymous said...

Captcha image disappears as soon as I sign out and come back to the captcha page. It never comes back again. Please help me out.

Thanks
Raj.

Anonymous said...

Captcha image disappears after logout. And it never comes back. Please help me out!

Turin said...

Thank you very much.
Nice and easy.

Anonymous said...

Obviously new to ASP/AJAX by this comment ....
What is meant by "Refer the assembly CaptchaDLL.dll in your project" and how do you it?

Scott

Anzer said...

@Raj
I think the folder contaning JpegImage_CS.aspx (JpegImage_VB.aspx ) does not have anonymous permission.. Try accessing the page directly (like http://localhost/yoursite/JpegImage_CS.aspx ) and see whether its redirecting to login page...
If so you need to give anonymouse permission to that file...
See thios link to know how you can exclude a page from security settings...
http://support.microsoft.com/kb/316871

Anzer said...

@Scott
You need to add reference of that assembly in your project..
In the Visual studio right click on the solution explorer and select Add reference.. now go to Browse tab and browse the CaptchaDLL.dll from the downloaded source.. click OK'..

See the following links for more details
http://msdn.microsoft.com/en-us/library/wkze6zky(VS.80).aspx

http://www.csharp411.com/adding-assemblies-to-the-visual-studio-add-reference-dialog/

Regards
Anz

Unknown said...

Thanks for the reply. I found that about an hour ago online.

Now the problem is that the Captcha image is not appearing. I have this in a login control. Funny thing is that if I replace the src="JpegImage_VB.aspx" with a graphic from my Images folder, the image doesn't display either.

The JpegImage_VB.aspx file is in the sites root directory. When I start with debugging and have a breakpoint in the JpegImage_VB.aspx file it doesn't appear the file is being executed.
When the login comes up, the alt text "Visual Verification" appears.

Any ideas?

Unknown said...

Sweet!!!!!!!!!!!!!!!
Looks Good.

Can't thank you enough for your help.

Anonymous said...

@Anzer

Thanks a lot! That worked!

Raj.

Anzer said...

@Scott
you got it working???
if no please refer to my reply to Raj.. that may be the reason the image not displaying

http://anzme.blogspot.com/2008/10/i-am-using-great-asp.html?showComment=1241716980000#c3538917920615613706

Unknown said...

cool sample.. thanks for sharing..

Jacques Nuss said...

Thanks very much! You saved me a week...!

Anonymous said...

Indeed, very nice! Thanks...

Anonymous said...

Thanks for the tool, may i know if it has the ability to switch to small and large cases, like "Djts7cjP"?

Anonymous said...

I'm sry but I'm new.
I've tryed for hour to put captcha in my web page but I can't do that the image don't appear I see the error "Visual Verification".
I'm not sure to have do right thing.
Can u tell step by step what I have to do?
What I must put in the folder and where? thx a lot
-BiFe-

Anonymous said...

Thanks for a wonderful control and the test project. Couldn't be more perfecter... (if thats a word)

Matt said...

Thanks for the CAPTCHA code, it works well. The only problem I'm having after inserting the code is that the refresh button has to be clicked once in order for the image to show up for the first time on page load. Is there something that needs to be called in the Page_Init or Page_Load for it to work properly?

Thanks for your help!

Anonymous said...

Great help for me!
Thanks a lot

Anthony

Search

Google