Diamond.Captcha 2025.0.0

dotnet add package Diamond.Captcha --version 2025.0.0
                    
NuGet\Install-Package Diamond.Captcha -Version 2025.0.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="Diamond.Captcha" Version="2025.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Diamond.Captcha" Version="2025.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Diamond.Captcha" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Diamond.Captcha --version 2025.0.0
                    
#r "nuget: Diamond.Captcha, 2025.0.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.
#:package Diamond.Captcha@2025.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Diamond.Captcha&version=2025.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Diamond.Captcha&version=2025.0.0
                    
Install as a Cake Tool

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.
  • 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 AddCachedCaptcha or AddDistributedCaptcha method.
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>

License

Apache-2.0 license

Product 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. 
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
2025.0.0 168 10/25/2025