ChatAIze.Captcha 0.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package ChatAIze.Captcha --version 0.3.0                
NuGet\Install-Package ChatAIze.Captcha -Version 0.3.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="ChatAIze.Captcha" Version="0.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ChatAIze.Captcha --version 0.3.0                
#r "nuget: ChatAIze.Captcha, 0.3.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.
// Install ChatAIze.Captcha as a Cake Addin
#addin nuget:?package=ChatAIze.Captcha&version=0.3.0

// Install ChatAIze.Captcha as a Cake Tool
#tool nuget:?package=ChatAIze.Captcha&version=0.3.0                

Captcha

C# .NET 8.0 Blazor server component for hCaptcha.

[!WARNING] This library is designed to be used in a Blazor server app with interactive rendering enabled. It does NOT support Blazor WebAssembly.

Installation

NuGet Package

NuGet CLI
dotnet add package ChatAIze.Captcha
Package Manager Console
Install-Package ChatAIze.Captcha

Service (Program.cs)

builder.Services.AddCaptcha(o =>
{
    o.SiteKey = builder.Configuration["Captcha:SiteKey"]!;
    o.Secret = builder.Configuration["Captcha:Secret"]!;
    o.VerifyIpAddresses = true; // optional, default is true
    o.IsConnectionProxied = false; // optional, default is false
});

[!NOTE] If users are connecting to your app via a reverse proxy like Cloudflare, IsConnectionProxied should be set to true. In such a case, the X-Forwarded-For header will be used to determine the client's IP address.

Middleware (Program.cs)

app.UseCaptcha();

Javascript (App.razor)

<head>
  
  <script src="https://js.hcaptcha.com/1/api.js" async defer></script>
  
</head>

Using (_Imports.razor)

@using ChatAIze.Captcha

Usage

<Captcha @bind-IsVerified="_isVerified" />
<h1>Verified: @_isVerified</h1>

@code {
    private bool _isVerified;
}

[!TIP] Make sure that the component containing the CAPTCHA has interactive rendering enabled.

@rendermode InteractiveServer

Properties

  • SiteKey: Overrides service settings
  • Secret: Overrides service settings
<Captcha @bind-IsVerified="_isVerified" SiteKey="" Secret="" />
  • Theme: Auto - Light - Dark
  • Size: Normal - Compact
<Captcha @bind-IsVerified="_isVerified" Theme="CaptchaTheme.Auto" Size="CaptchaSize.Normal" />

Events

  • Opened: Called when the user display of a challenge starts.
  • Closed: Called when the user dismisses a challenge.
  • Succeeded: Called when the user submits a successful response.
  • Expired: Called when the passcode response expires and the user must re-verify.
  • ChallengeExpired: Called when the user display of a challenge times out with no answer.
  • Error: Called when hCaptcha encounters an error and cannot continue.
<Captcha @bind-IsVerified="_isVerified" SiteKey="" Secret="" Theme="CaptchaTheme.Auto" Size="CaptchaSize.Normal" Opened="OnOpened" Closed="OnClosed" Succeeded="OnSucceeded" Expired="OnExpired" ChallengeExpired="OnChallengeExpired" Error="OnError" />

@code {
    private bool _isVerified;

    private void OnOpened() { }

    private void OnClosed() { }

    private void OnSucceeded() { }

    private void OnExpired() { }

    private void OnChallengeExpired() { }

    private void OnError(string code) { }

Errors

Code Description
rate-limited User has sent too many requests
network-error There are network connection issues (e.g., offline). hCaptcha will automatically retry.
invalid-data Invalid data is not accepted by endpoints
challenge-error Challenge encountered error on setup. User may need to select the checkbox or call execute.
challenge-closed User closed the challenge
challenge-expired Time limit to answer challenge has expired
missing-captcha No captcha was found. Verify hCaptcha was properly setup and a captcha was rendered.
invalid-captcha-id Captcha does not exist for ID provided. Check that the captcha rendered matches the stored ID.
internal-error hCaptcha client encountered an internal error. User may need to select the checkbox or call execute.
script-error hCaptcha JS SDK could not be loaded. User may be behind a firewall blocking api.js.

Source: https://docs.hcaptcha.com/configuration#error-codes

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.

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
0.4.2 76 12/18/2024
0.4.1 93 12/6/2024
0.4.0 116 11/17/2024
0.3.1 114 11/13/2024
0.3.0 111 11/11/2024
0.2.0 115 11/11/2024
0.1.0 105 11/11/2024