Internal Sitepoint library providing integration with the self-hosted ALTCHA proof-of-work CAPTCHA service. Includes the client-side ALTCHA widget (static assets) and a typed service layer for requesting challenges and verifying proofs against the private backend API.
$ dotnet add package Sitepoint.AltchaCaptchaSitepoint.AltchaCaptcha is a lightweight community C# integration package for the ALTCHA proof-of-work CAPTCHA system.
It provides:
IOptions<T>)Add the NuGet package:
dotnet add package Sitepoint.AltchaCaptcha
In your Program.cs:
builder.Services.AddAltchaCaptcha(options =>
{
options.ApiKey = builder.Configuration["SitepointCaptcha:ApiKey"]!;
options.SiteKey = builder.Configuration["SitepointCaptcha:SiteKey"]!;
options.VerifyChallengeUrl = builder.Configuration["SitepointCaptcha:VerifyUrl"]!;
});
In a Razor view or partial:
<script src="/altcha-widget.js" type="module"></script>
<form method="post" asp-action="Submit">
<altcha-widget challengeurl="https://localhost:5000//captcha/generate/<siteKey>"></
<altcha-widget>
<button type="submit">Submit</button>
</form>
In your controller:
public class ContactController : Controller
{
private readonly ICaptchaValidationService _captchaValidationService;
public ContactController(ICaptchaValidationService captchaValidationService) => _captchaValidationService = captchaValidationService;
[HttpPost]
public async Task<IActionResult> Submit(ContactFormModel model)
{
if (!ModelState.IsValid)
{
return CurrentUmbracoPage();
}
var validationResult = await _captchaValidationService.ValidateAsync(HttpContext.Request.Form["altcha"]);
if (!validationResult.IsValid)
{
TempData["CaptchaNotValid"] = true;
return CurrentUmbracoPage();
}
TempData["FormSubmitted"] = true;
return RedirectToCurrentUmbracoPage();
}
}
This package is licensed under the MIT License (see LICENSE file).
Portions of this software are derived from the ALTCHA project and the Ixnas.AltchaNet C# library, both licensed under MIT.
This package is developed and maintained by Site Point as a community C# integration layer for self-hosted ALTCHA deployments.