ChatAIze.Captcha
0.4.2
dotnet add package ChatAIze.Captcha --version 0.4.2
NuGet\Install-Package ChatAIze.Captcha -Version 0.4.2
<PackageReference Include="ChatAIze.Captcha" Version="0.4.2" />
paket add ChatAIze.Captcha --version 0.4.2
#r "nuget: ChatAIze.Captcha, 0.4.2"
// Install ChatAIze.Captcha as a Cake Addin #addin nuget:?package=ChatAIze.Captcha&version=0.4.2 // Install ChatAIze.Captcha as a Cake Tool #tool nuget:?package=ChatAIze.Captcha&version=0.4.2
CAPTCHA
C# .NET 9.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 = false; // optional, default is false
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 totrue
. In such a case, theX-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. |
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. |
-
net9.0
- Microsoft.AspNetCore.Components.Web (>= 9.0.0)
- Microsoft.AspNetCore.Http (>= 2.2.2)
- Microsoft.Extensions.Http (>= 9.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.