Captcha TagHelper Overview

The Telerik UI Captcha for ASP.NET Core is a security measure that prevent automated spam from performing tasks such as form submissions in your ASP.NET Core application. The widget generates distorted images of letters and numbers that are easily decipherable to humans, but not to automated programs (spam bots).

Telerik UI for ASP.NET Core Ninja image

The Captcha is part of Telerik UI for ASP.NET Core, a professional grade UI library with 110+ components for building modern and feature-rich applications. To try it out sign up for a free 30-day trial.

Basic Configuration

The Captch TagHelper configuration options are passed as attributes of the tag.

<kendo-form name="form" form-data="@Model">
    <form-items>
        <form-item field="UserName"></form-item>
        <form-item field="FirstName"></form-item>
        <form-item field="LastName"></form-item>
        <form-item field="Captcha">
            <captcha-editor datacaptchaidfield="CaptchaID" datacaptchafield="Captcha" captcha-image="@ViewData["Captcha"]" captcha-id="@ViewData["CaptchaID"]">
                <handler url="@Url.Action("Reset")" />
                <validation-handler url="@Url.Action("Validate")" />
                <audio-handler function-handler="audioHandler" />
            </captcha-editor>
        </form-item>
    </form-items>
</kendo-form>
public ActionResult Reset()
{
    CaptchaImage newCaptcha = SetCaptchaImage();

    return Json(new CaptchaModel
    {
        Captcha = "./shared/UserFiles/captcha/" + newCaptcha.UniqueId + ".png",
        CaptchaID = newCaptcha.UniqueId
    });
}

public ActionResult Validate(CaptchaModel model)
{
    string text = GetCaptchaText(model.CaptchaID);

    return Json(text ==  model.Captcha.ToUpperInvariant());
}

private string GetCaptchaText(string captchaId)
{
    string text = HttpContext.Session.GetString("captcha_" + captchaId);

    return text;
}

To ensure that the server-side image generation and validation is handled by the widget, add the Telerik UI Captcha server-side provider.

See Also

In this article
Not finding the help you need? Improve this article