BlazorReCaptcha 1.0.1

dotnet add package BlazorReCaptcha --version 1.0.1
NuGet\Install-Package BlazorReCaptcha -Version 1.0.1
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="BlazorReCaptcha" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlazorReCaptcha --version 1.0.1
#r "nuget: BlazorReCaptcha, 1.0.1"
#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.
// Install BlazorReCaptcha as a Cake Addin
#addin nuget:?package=BlazorReCaptcha&version=1.0.1

// Install BlazorReCaptcha as a Cake Tool
#tool nuget:?package=BlazorReCaptcha&version=1.0.1

BlazorReCaptcha Component

BlazorReCaptcha is a Blazor component that simplifies the integration of Google's reCAPTCHA v2 into your Blazor applications. This component allows you to easily add reCAPTCHA capabilities to your forms and handle client-side and server-side validation.

Prerequisites

Before using this component, ensure that you have the following:

  • Google reCAPTCHA API Keys: You need a Site Key and a Secret Key from the reCAPTCHA website for the component to work correctly.

Installation

To use BlazorReCaptcha in your Blazor application, you can install the NuGet package:

dotnet add package BlazorReCaptcha

Usage

  1. Add the script reference to your app.razor
<script src="_content/BlazorReCaptcha/BlazorReCaptcha.js"></script>
  1. Add the component to your Razor page or component
<ReCaptcha @ref="reCaptcha" SiteKey="your_site_key" Secret="your_secret_key" OnClientSuccess="OnClientSuccess" OnExpired="OnExpired" />

or

<ReCaptcha @ref="reCaptcha" OnClientSuccess="OnClientSuccess" OnExpired="OnExpired" />
  1. Handle success and expiration events
@code {
    async Task HandleClientSuccess()
    {
        // Handle client-side success
    }

    async Task HandleExpired()
    {
        // Handle expiration
    }
}
  1. Accessing reCAPTCHA response in code
var response = await captcha.GetResponseAsync();
  1. Verify the reCAPTCHA response on the server
var verificationResult = await captcha.Verify(response);

Parameters

  • SiteKey: Your reCAPTCHA Site Key.
  • Secret: Your reCAPTCHA Secret Key.
  • OnClientSuccess: Event callback
async Task HandleClientSuccess(string response)
{
    // Handle client-side success
}
  • OnExpired: Event callback
async Task HandleExpired()
{
    // Handle expiration
}

Examples

For a complete example of how to use this component, check the BlazorReCaptchaSample in this repository.

Configuration

You can configure the reCAPTCHA keys in your appsettings.json file:

{
  "ReCaptcha": {
    "Sitekey": "your_site_key",
    "Secret": "your_secret_key"
  }
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Feel free to contribute, open issues, or provide feedback to make this component even better!

Product Compatible and additional computed target framework versions.
.NET 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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
1.0.1 179 12/12/2023
1.0.0 86 12/11/2023