NSCaptcha 1.0.0

dotnet add package NSCaptcha --version 1.0.0                
NuGet\Install-Package NSCaptcha -Version 1.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="NSCaptcha" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add NSCaptcha --version 1.0.0                
#r "nuget: NSCaptcha, 1.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.
// Install NSCaptcha as a Cake Addin
#addin nuget:?package=NSCaptcha&version=1.0.0

// Install NSCaptcha as a Cake Tool
#tool nuget:?package=NSCaptcha&version=1.0.0                

NSCaptcha-Photoroom

A .NET library for easy CAPTCHA integration

NuGet

Features

  • Easy Integration: Seamlessly integrate CAPTCHA into your ASP.NET, WPF, or any other .NET project.
  • Customizable: Configure CAPTCHA appearance, difficulty, and behavior to suit your specific needs.
  • High Security: Robust CAPTCHA generation and validation mechanisms to prevent bots and automated attacks.
  • Cross-Platform: Compatible with various .NET platforms and operating systems.

License

MIT

Installation

  1. Install via NuGet Package Manager:

    • Open the NuGet Package Manager in Visual Studio.
    • Search for "NSCaptcha" in the package manager.
    • Select the "NSCaptcha" package and click "Install."
    • Accept the license agreement (if applicable).
  2. Install via .NET CLI:

    • Open a command prompt or terminal window.

    • Navigate to your project's directory.

    • Use the following command:

      dotnet add package NSCaptcha
      

Usage

Refer to the documentation: Detailed usage examples and API documentation are available within the package or on the project website.

Default Configuration

builder.Services.AddDataProtection().SetApplicationName("<Your App Name>").PersistKeysToFileSystem(new DirectoryInfo(Path.Combine("<File Location In System>")));
builder.Services.AddMemoryCache();

captchaBuilder.AddCaptcha(new CaptchaOptions(new TimeSpan(0, 0, 30)))
    .AddCaptchaTokenEncryptionService<DefaultDataProtectionService>()
    .AddCaptchaTokenSerializer<InCookieCaptchaTokenSerializer>()
    .AddCaptchaTokenCacheService<InMemoryCaptchaTokenCacheService>()
    .Build();

After App Build

app.Use(async (context, next) =>
{
    context.Request.EnableBuffering();
    await next();
});

Create Captcha

[Route("api/captcha/create")]
[ApiController]
public class CreationController : ControllerBase
{
    private readonly ICaptchaServices _captchaService;
    public CreationController(ICaptchaServices captchaService)
    {
        _captchaService = captchaService;
    }

    [Route("image")]
    [HttpGet]
    public async Task<FileContentResult> GetImage()
    {
        var captcha = _captchaService.Create();

        return new FileContentResult(captcha.Image, "image/png");
    }
}

Validate Captcha

  • Add [ValidateCaptcha] attribute top of your validation action method
    [Route("validate")]
    [HttpPost]
    [ValidateCaptcha]
    public async Task Validate([FromBody] CaptchaTest value)
    {
        
    }

Note:

  • Replace <File Location In System> with the actual path to store the data protection keys.
  • You can use another options instead PersistKeysToFileSystem to configure the data protection system to persist keys
  • Notice that your property that you send as captcha value must has "CaptchaValue" name.
  • This is a basic example. You can customize it further based on your specific requirements and preferences.

Project Structure

The project follows a well-organized structure:

  • Filters: Contains filters for validating CAPTCHA responses.
  • Models: Contains data models used by the library (e.g., CaptchaOptions, RandomStringModel).
  • Services: Contains interfaces and implementations of services related to CAPTCHA (e.g., token generation, caching).
  • Signatures: Contains interfaces for various components of the CAPTCHA system.
  • Utilities: Contains helper classes and methods.

Contributing

Contributions are welcome! Please submit pull requests or create issues on the GitHub repository.

Product Compatible and additional computed target framework versions.
.NET 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. 
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
1.0.0 4 1/29/2025