Pandorax.Recaptcha 3.1.0

dotnet add package Pandorax.Recaptcha --version 3.1.0
                    
NuGet\Install-Package Pandorax.Recaptcha -Version 3.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Pandorax.Recaptcha" Version="3.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Pandorax.Recaptcha" Version="3.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Pandorax.Recaptcha" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Pandorax.Recaptcha --version 3.1.0
                    
#r "nuget: Pandorax.Recaptcha, 3.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Pandorax.Recaptcha@3.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Pandorax.Recaptcha&version=3.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Pandorax.Recaptcha&version=3.1.0
                    
Install as a Cake Tool

Pandorax.Recaptcha

This project is a library for validating Google reCAPTCHA responses in .NET applications.

Installation

To install the library, add the following NuGet package to your project:

dotnet add package Pandorax.Recaptcha

Usage

Configuration

First, configure the reCAPTCHA options in your appsettings.json:

{
  "Recaptcha": {
    "SiteKey": "your-site-key",
    "SecretKey": "your-secret-key"
  }
}

Then, register the reCAPTCHA services in your Startup.cs or Program.cs:

public void ConfigureServices(IServiceCollection services)
{
    services.AddRecaptcha(Configuration.GetSection("Recaptcha"));
}

Or, if you are using Program.cs with top-level statements:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddRecaptcha(builder.Configuration.GetSection("Recaptcha"));

Validation

When validating a reCAPTCHA response, you should check the following properties on the validation response:

  • Success: Indicates whether the validation was successful.
  • Score: Represents the confidence score (for reCAPTCHA v3). You may want to set a threshold (e.g., 0.5).
  • Action: Should match the expected action you specified when rendering the reCAPTCHA widget.

To validate a reCAPTCHA response, inject the IRecaptchaService into your controller or service and call the ValidateAsync method:

public class MyController : Controller
{
    private readonly IRecaptchaService _recaptchaService;

    public MyController(IRecaptchaService recaptchaService)
    {
        _recaptchaService = recaptchaService;
    }

    [HttpPost]
    public async Task<IActionResult> SubmitForm(string recaptchaResponse)
    {
        var validationResponse = await _recaptchaService.ValidateAsync(recaptchaResponse, HttpContext.Connection.RemoteIpAddress);

        if (validationResponse.Success)
        {
            // reCAPTCHA validation succeeded
            if (validationResponse.Score >= 0.5)
            {
                // High confidence in the user's interaction
                if (validationResponse.Action == "submit_form")
                {
                    // Action matches expected value
                }
                else
                {
                    // Action does not match expected value
                }
            }
            else
            {
                // Low confidence in the user's interaction
            }
        }
        else
        {
            // reCAPTCHA validation failed
        }

        return View();
    }
}

License

This project is licensed under the MIT License.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Pandorax.Recaptcha:

Package Downloads
Pandorax.Recaptcha.DependencyInjection

Pandorax.Recaptcha extensions for ASP.NET Core

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.1.0 137 6/2/2025
3.1.0-alpha001 138 6/2/2025
3.0.0 132 6/2/2025
3.0.0-alpha003 115 2/13/2025
3.0.0-alpha002 734 10/20/2022
3.0.0-alpha001 214 10/13/2022
2.1.1 9,622 10/6/2021
2.1.0 743 7/14/2021 2.1.0 is deprecated because it is no longer maintained and has critical bugs.
2.0.1 749 5/26/2021
1.2.0 3,198 2/24/2020
1.1.0 544 2/24/2020
1.0.0-alpha1 972 11/26/2019