How to Add a Captcha Image in ASP.NET Application

There are some steps to Add Captcha image in Asp.NET Application. You can download whole application from below link.You can easily add this captcha image to your Asp.Net Application Without facing any problem. You can add another captcha code also in any asp.net application from here.Both captcha codes will be provided full security to your asp.net application. Please follow these  steps one by one which are given below.
Step1:- First create ASP.NET page (Default.aspx) in visual studio 2010--> Now click the below link to download the captcha.dll file.
see captcha.dll file:-
MSCaptcha.dll
Step2:-Now Open Solution Explorer -->Add new Folder(Bin)->open the captcha.dll file->copy all the file -> Now paste it in the Bin Folder.
see it:-
paste_dll

Step3:- Now Write the code for captcha control in Source file as shown below:
see it:-
design_mode

Step4:-  Now Drag and Drop Text-box,Button, Label and Validation controls on Default.aspx page from the Toolbox.which is as shown below:-
see it:-
validation_control

Step5:- Now Double click on Button control(Verify) and write the following code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        captcha1.ValidateCaptcha(TextBox2.Text.Trim());
        if (captcha1.UserValidated)
        {
          Label1.ForeColor = System.Drawing.Color.Green;
          Label1.Text = "You have Entered Valid Captcha Characters";
        }
        else
        {
            Label1.ForeColor = System.Drawing.Color.Red;
            Label1.Text = "You have Entered InValid Captcha Characters please Enter again";
        }
    }
}

see it:-

c#_codes

Step6:- Now open the web.config file and write the following codes as shown below.
see it:-

web.config

Step7:- Run the Application (press F5).
see it:
OUTPUT:-
  • when we Enter the  correct captcha image In the  Text-Box and click Verify Button,then we see following output:-
output

  • when we Enter the Incorrect captcha image In the  Text-Box and Click Verify Button,then we see following output :
output

 Download whole attached application.
         DOWNLOAD

19 comments:

  1. the characters matching with the captcha image characters are not case sensitive.I need to make a case sensitive match. Can some one help.

    ReplyDelete
  2. thanx my friends, I am comming soon for new post.many times i have not written any post because i was doing training from C-dac in SECURITY Domain. Now i finished it now again i will write some good post which is helpful for learner(YOU).

    ReplyDelete
  3. code is perfect.. bt itz not displaying the catcha image and so I cnt even enter the text.. plz help.. do revert back on steffi.aiesec@gmail.com

    ReplyDelete
  4. This code is not working in Framework 3.5. Is there any updation to be done in the code?
    Without this captcha my main project is not working. Kindly help me to solve the problem.

    ReplyDelete
  5. hii,

    im getting this error

    in default.aspx file

    element CaptchaControl is not a known element

    ReplyDelete
  6. Goodone I'll try it and use it on my website www.jokeshindi.com

    ReplyDelete
  7. Warning 1 Unable to update auto-refresh reference 'mscaptcha.dll'. Cannot find assembly 'D:\Documents and Settings\Administrator\Desktop\mscaptcha\MSCaptcha.dll'. C:\Users\HRAMAN\Documents\Visual Studio 2012\captcha\Bin\mscaptcha.dll.refresh captcha

    ReplyDelete
  8. if you are using my application,then first delete all mscaptcha.dll file from bin folder.close your application,after that open -->go bin folder and paste the all mscaptcha.dll file from step 1. you can use captcha image on your website without dll file Read it:-
    http://www.msdotnet.co.in/2013/09/how-to-create-captcha-image-without-dll.html

    ReplyDelete
  9. how to create a newfolder ,if a am creating the bin folder it is already exist how to I create a bin folder

    ReplyDelete
  10. iMAGE GENERATION IS NOT TAKING PLACE....

    ReplyDelete
  11. Error Creating Control - captcha1Unknown server tag 'rsv:CaptchaControl'...This error is coming..what is the solution???

    ReplyDelete
    Replies
    1. hi priya , try again ,otherwise download whole application from below and run directly on your visual studio .it will definitely work.........

      Delete
  12. My Captcha Image is Not displying i use same code..........
    and also try in different browser also............!!

    help me............

    ReplyDelete
    Replies
    1. it is working try again carefully...........

      Delete
  13. "TagePrefix" attribute missing and unknown server tag 'rsv:CaptchaControl '
    help me

    ReplyDelete
    Replies
    1. you have not follow each steps correctly.see step 3 carefully ,try again with fresh application.it will work definitely.if you face problem again,contact me through contact form.

      Delete
  14. SIR please upload wpf tutorial with examples

    ReplyDelete

@2012-2014 msdotnet. All Rights Reserved. Don't Copy