CMS365.BlazoredGoogleCaptcha 9.0.5

There is a newer version of this package available.
See the version list below for details.
dotnet add package CMS365.BlazoredGoogleCaptcha --version 9.0.5
                    
NuGet\Install-Package CMS365.BlazoredGoogleCaptcha -Version 9.0.5
                    
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="CMS365.BlazoredGoogleCaptcha" Version="9.0.5" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CMS365.BlazoredGoogleCaptcha" Version="9.0.5" />
                    
Directory.Packages.props
<PackageReference Include="CMS365.BlazoredGoogleCaptcha" />
                    
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 CMS365.BlazoredGoogleCaptcha --version 9.0.5
                    
#r "nuget: CMS365.BlazoredGoogleCaptcha, 9.0.5"
                    
#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 CMS365.BlazoredGoogleCaptcha@9.0.5
                    
#: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=CMS365.BlazoredGoogleCaptcha&version=9.0.5
                    
Install as a Cake Addin
#tool nuget:?package=CMS365.BlazoredGoogleCaptcha&version=9.0.5
                    
Install as a Cake Tool

BlazoredGoogleCaptcha: Google reCAPTCHA V1 and V2 for Blazor

NuGet NuGet Downloads GitHub last commit (main) License GitHub Stars

BlazoredGoogleCaptcha is a lightweight .NET library that simplifies Google reCAPTCHA integration in Blazor WebAssembly (WASM) and Blazor Server applications. It provides an easy-to-use component for both reCAPTCHA v2 ("I'm not a robot" checkbox) and reCAPTCHA v3 (invisible background verification).

Installation

BlazoredGoogleCaptcha is available on NuGet. Use the package manager console in Visual Studio to install it:

Install-Package CMS365.BlazoredGoogleCaptcha

Getting started

Navigate to https://www.google.com/recaptcha/admin/create and register 2 sites.

Select "Score based (v3)" for the first site and "Checkbox (v2)" for the second site. alt text Add demain, for example localhost for testing purposes.

Also select Google Cloud Platform project, if you have one, or create a new one.

Once the projct has been created, click on the settings icon in the top right corner of the page and copy the site key and secret key for both reCAPTCHA v2 and v3.

alt text

alt text

Install the package and create 2 seperate pages for V2 and V3 reCAPTCHA.

In the demo project, I have created 2 pages : 'CounterV2.razor' and 'CounterV3.razor'.

alt text

V2 ReCaptcha

Add the following code to your Program.cs file to register the CaptchaService and configure the BlazoredGoogleCaptcha component:

builder.Services.AddSingleton<CaptchaService>();

Open the 'CounterV2.razor' page and add the following code:

@page "/counterv2"

@rendermode InteractiveServer

@using BlazoredGoogleCaptcha.Responses
@using BlazoredGoogleCaptcha.Services

@inject IConfiguration configuration
@inject CaptchaService captchaService

<PageTitle>Counter</PageTitle>
<h1>Counter</h1>

<p role="status">Current count: @currentCount</p>

<Captcha SiteKey="@configuration["v2SiteKey"]" OnSuccess="@OnCaptchaSuccess" OnExpired="@OnCaptchaExpired"></Captcha>
<button class="btn btn-primary" @onclick="IncrementCount" disabled="@IsButtonDisabled">Click me</button>

@code {
    private int currentCount = 0;
    private bool captchaVerified = false;
    private bool IsButtonDisabled => !captchaVerified;

    private void IncrementCount()
    {
        currentCount++;
    }
    private async void OnCaptchaSuccess(string response)
    {
        string? captchaSecret = configuration["v2SecretKey"];
        CaptchaV2Response? captchaResponse = await captchaService.VerifyV2(captchaSecret, response);
        if (captchaResponse.Success)
        {
            captchaVerified = true;
            StateHasChanged();
        }
        else
        {
            //show error message or handle failure
        }
    }
    private void OnCaptchaExpired()
    {
        captchaVerified = false;
    }
}

By default, V2 will be rendered.

In the example aboue, I have the counter button disbaled on the page load.

alt text

Once the user clicks on the reCAPTCHA checkbox and passes the verification, the button will be enabled.

alt text

Product Compatible and additional computed target framework versions.
.NET 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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.6 296 6/13/2025
9.0.5 235 6/13/2025
9.0.4 238 6/13/2025
9.0.3 246 6/13/2025
9.0.2 248 6/13/2025
9.0.1 254 6/13/2025