Simple Captcha solution
Simple Captcha solution for protecting web forms from non-human submissions. This
is how the image would look like:
(click the image for source code)
It looks different every time you reload
the page. It can be customized.
Build the method for processing the submission:
protected void Submit_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
// your code here
}
}
Put the validator event into code:
protected void CaptchaValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
args.IsValid = captcha.Text.Equals((string)Session["captcha"], StringComparison.OrdinalIgnoreCase);
}
Put the image and input box on the page:
<img runat="server" alt="captcha" align="left" src="~/captcha.aspx" />
<asp:TextBox ID="captcha" runat="server" Width="80" />
Put validators on the page:
<asp:RequiredFieldValidator runat="server" ErrorMessage="*" ControlToValidate="captcha" />
<asp:CustomValidator runat="server" ErrorMessage="*" ControlToValidate="captcha" OnServerValidate="CaptchaValidator_ServerValidate" />
Add the Captcha Image Generator page to your site.