Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Sir,
I am using Captcha Control in ASP.NET.On design page i have textbox ,button and captcha control. now i want that when i enter the same text as captcha in textbox and click on button than check that entered text is match or not.
So i want to put the validation to check that entered text is match with captcha code.
And if doesn't match then give an error message.

Thank You.
Posted

check condition like that.
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        CaptchaControl1.ValidateCaptcha(TextBox1.Text);
        if (!CaptchaControl1.UserValidated)
        {
            Label1.Text = " not sucessfull";
            return;
        }
        else
        {
            Label1.Text = "Sucessfull";
        }
}
 
Share this answer
 
v2
Comments
Priyaaammu 24-Jul-12 3:22am    
i tried this code...but even after correct code is given,"not successful" message only displayed...any help
Have a look at these articles on how Captcha works:
CAPTCHA Image[^]
Simple ASP.NET CAPTCHA Tutorial [^]

If you are still stuck, post the code, work you did and where you are unable to get it. All you need is to compare and then raise the flag based on the comparison result.
 
Share this answer
 
Comments
SURBHI TYAGI 5-May-11 2:37am    
okss......
SURBHI TYAGI 5-May-11 2:41am    
i m not using session here.i am using a captcha control.so now how i work?
Sandeep Mewara 5-May-11 3:06am    
No idea what you are talking of. On button click, all you need is to verify the text entered with the actual text in captcha which you can always have stored in a hidden field or extract directly.
NuttingCDEF 5-May-11 5:17am    
It feels as though this defeats the point of a CAPTCHA - if the required text can be extracted from what is rendered to the user's browser (e.g. from a hidden field or from the CAPTCHA image) then you lose the protection the CAPTCHA provides.

You need to generate your CAPTCHA text server side, store it server side, generate the image rendered to the user, then on postback compare the text the user entered with what you have stored on the server.

Your web server may be handling multiple concurrent clients, with different text, so you need some way to work out which text is right for each postback.

Inevitably, this means either storing the required text in the user's session - or maybe using a key / value mechanism (key is just an index that can be sent to the user in a hidden field - value is the relevant text) so on postback, use the posted back key to look up what text is expected to compare with the text the user entered. Note that with a key/value mechanism you also need to delete each pair after it has been used (or after a timeout if unused) to avoid replay attacks.

So session or database or some other storage mechanism is required - maybe hold everything in memory if you know you will never have more than a few users.
SURBHI TYAGI 5-May-11 3:09am    
i have also no idea.i am using it first time.so could you help me how to work?directly i am using catchacontrol from toolbox.after that i don't understand that how to work on it?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900