Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/chataize/captcha
C# .NET 9.0 Blazor server component for hCaptcha.
https://github.com/chataize/captcha
app asp-net-core blazor bot captcha chataize component control csharp dotnet hcaptcha human interactive lib library protection razor server verification web
Last synced: about 10 hours ago
JSON representation
C# .NET 9.0 Blazor server component for hCaptcha.
- Host: GitHub
- URL: https://github.com/chataize/captcha
- Owner: chataize
- License: gpl-3.0
- Created: 2024-11-10T22:34:21.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-12-18T09:43:24.000Z (26 days ago)
- Last Synced: 2024-12-18T10:36:27.814Z (26 days ago)
- Topics: app, asp-net-core, blazor, bot, captcha, chataize, component, control, csharp, dotnet, hcaptcha, human, interactive, lib, library, protection, razor, server, verification, web
- Language: CSS
- Homepage: https://www.chataize.com
- Size: 146 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# CAPTCHA
C# .NET 9.0 Blazor server component for [hCaptcha](https://www.hcaptcha.com).> [!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
```bash
dotnet add package ChatAIze.Captcha
```
#### Package Manager Console
```powershell
Install-Package ChatAIze.Captcha
```
### Service (Program.cs)
```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](https://www.cloudflare.com), `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)
```cs
app.UseCaptcha();
```
### Javascript (App.razor)
```html
```
### Using (_Imports.razor)
```razor
@using ChatAIze.Captcha
```## Usage
```razorVerified: @_isVerified
@code {
private bool _isVerified;
}
```
> [!TIP]
> Make sure that the component containing the CAPTCHA has **interactive rendering** enabled.
> ```razor
> @rendermode InteractiveServer
> ```
### Properties
- **SiteKey**: Overrides service settings
- **Secret**: Overrides service settings
```razor```
- **Theme**: Auto - Light - Dark
- **Size**: Normal - Compact
```razor```
### 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.
```razor@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