Diamond.Captcha
2025.0.0
dotnet add package Diamond.Captcha --version 2025.0.0
NuGet\Install-Package Diamond.Captcha -Version 2025.0.0
<PackageReference Include="Diamond.Captcha" Version="2025.0.0" />
<PackageVersion Include="Diamond.Captcha" Version="2025.0.0" />
<PackageReference Include="Diamond.Captcha" />
paket add Diamond.Captcha --version 2025.0.0
#r "nuget: Diamond.Captcha, 2025.0.0"
#:package Diamond.Captcha@2025.0.0
#addin nuget:?package=Diamond.Captcha&version=2025.0.0
#tool nuget:?package=Diamond.Captcha&version=2025.0.0
Diamond.Captcha Package
A lightweight and dependency-free Captcha generation package for ASP.NET Core. the Diamond.Captcha generates Captcha images entirely in-memory without relying on any external graphic libraries with zero dependency .
Features
- No external graphic library dependencies: Pure in-memory Captcha image generation.
- Supports two operational modes:
- CachedCaptcha: Stores Captcha data in
IMemoryCache. - DistributedCaptcha: Uses AES encryption to store Captcha data, enabling validation across multiple distributed servers.
- CachedCaptcha: Stores Captcha data in
- Easy to integrate with ASP.NET Core applications.
- Secure Captcha validation for both single-server and distributed environments.
How It Works
The Diamond.Captcha generates the Captcha image dynamically in memory and embeds the corresponding code in either:
- An in-memory cache for quick access and validation (
CachedCaptcha). - An encrypted token sent along with the response for stateless validation across distributed servers (
DistributedCaptcha).
This design eliminates the need for external storage or graphic libraries and supports scalable, secure web applications.
Usage and Example
In Program.cs:
- Diamond.Captcha is enabled with the
AddCachedCaptchaorAddDistributedCaptchamethod.
using Microsoft.Extensions.DependencyInjection;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddCachedCaptcha();
//builder.Services.AddDistributedCaptcha(options => options.CryptographyKey = "YOUR_AES_KEY");
var app = builder.Build();
app.Run();
In HomeController.cs:
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Html;
using Diamond.AspNetCore.Html.Captcha;
public class HomeController : Controller
{
private readonly ICachedCaptcha m_Captcha;
public HomeController(ICachedCaptcha captcha)
{
this.m_Captcha = captcha;
}
[HttpGet]
public IActionResult Index()
{
return this.View();
}
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Index(string Captcha_RefID, string Input_Captcha)
{
if (this.m_Captcha.Validate(Captcha_RefID, Input_Captcha))
{
return this.Ok("Captcha validated successfully");
}
else
{
return this.BadRequest("Invalid Captcha");
}
}
public IActionResult CaptchaImage(string id, int version = 0)
{
return this.m_Captcha.GetImage(id, version);
}
}
In Index.cshtml:
@inject Diamond.AspNetCore.Html.Captcha.ICachedCaptcha captcha
@{
string captchaRefID = captcha.NewRefID();
}
<form asp-antiforgery="true">
<input type="hidden" id="Captcha_RefID" name="Captcha_RefID" value="@captchaRefID" />
<input type="text" name="Input_Captcha" autocomplete="off" autocorrect="off" />
<img id="CaptchaImage" src="/Home/CaptchaImage/@captchaRefID" />
<a href="#" onclick="OnCaptchaRefresh()">Refresh</a>
<script language="javascript">
var version = 0;
function OnCaptchaRefresh()
{
version++;
var img = document.getElementById("CaptchaImage");
img.src = "/Home/CaptchaImage/@captchaRefID?version=" + version;
return false;
}
</script>
</form>
Links
License
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.AspNetCore.Mvc (>= 2.0.0)
- System.Memory (>= 4.5.0)
-
.NETStandard 2.0
- Microsoft.AspNetCore.Mvc (>= 2.0.0)
- System.Memory (>= 4.5.0)
-
.NETStandard 2.1
- Microsoft.AspNetCore.Mvc (>= 2.1.0)
-
net6.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.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 |
|---|---|---|
| 2025.0.0 | 168 | 10/25/2025 |