BlazorVerificationCaptcha 0.1.2

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

// Install BlazorVerificationCaptcha as a Cake Tool
#tool nuget:?package=BlazorVerificationCaptcha&version=0.1.2                

BlazorVerificationCaptcha

The BlazorVerificationCaptcha project offers a seamless solution for integrating CAPTCHA verification into Blazor applications. Utilizing this package allows developers to quickly and effortlessly enhance their application's security by verifying users and safeguarding against automated bots.

Check it out on GitHub: https://github.com/liebki/BlazorVerificationCaptcha

Technologies

Created using

  • .NET Core 6.0

NuGet/Dependencies used

Features

Nuget

General

  • Provides a simple and easy-to-use solution for implementing captcha verification in Blazor applications.
  • You can change the image quality, length of the captcha text, what should be displayed, make it easier or harder to read etc.

Screenshots

A GIF, to see the image and variable content change on page reload

Animated

A image, to get the original quality that the image is displayed in

Static

Usage (For more, see examples)

To seamlessly integrate BlazorVerificationCaptcha into your Blazor application, follow these simple steps:

  1. Install the Package: Begin by installing the BlazorVerificationCaptcha package from NuGet. This can be done using your preferred package manager.

  2. Import the Namespace: In your Blazor project, add @using BlazorVerificationCaptcha to the _Imports.razor file. This enables you to use the package's features throughout your application.

  3. Implement the Captcha Component: Integrate the CAPTCHA component by placing the <VerificationCaptcha /> tag in the desired location within your Blazor components. This tag will render the CAPTCHA image.

  4. Generate CAPTCHA Content: Inside the OnInitializedAsync() method or another suitable lifecycle method, include the code snippet ExampleVariable = VerificationCaptcha.GenerateCaptchaContent();. This line of code generates the CAPTCHA image and text content, which can be used as needed in your application.

By following these steps, you'll effectively incorporate BlazorVerificationCaptcha to enhance security and user interaction in your Blazor application.

For more comprehensive examples and usage scenarios, refer to the examples section below.

Example (Component)

Parameters

The GenerateCaptchaContent method inside the VerificationCaptcha class, allows you to generate CAPTCHA content, which includes both an image and the corresponding text. The method provides several customizable options to tailor the generated CAPTCHA according to your needs:

  • IncludeNumbers (Optional, default: true): Set this parameter to true if you want to include numbers in the CAPTCHA text. If set to false, only alphabetic characters will be used in the text.

  • TypefaceFamilyName (Optional, default: "Arial"): Specify the font family name for the CAPTCHA text. You can set this parameter to the desired font family name that suits your application's visual style.

  • CaptchaLength (Optional, default: 6): This parameter determines the desired length of the CAPTCHA text. You can set it to any positive integer value to control the length of the generated text.

  • JpegQualityLevel (Optional, default: 100): The JPEG quality level for image encoding defines the level of compression applied to the generated CAPTCHA image. Higher values result in higher image quality and larger file sizes, while lower values decrease image quality and file size.

  • ReduceRandomCharacters (Optional, default: false): When this parameter is set to true, certain characters in the generated image will have reduced randomness. This can make the CAPTCHA text slightly more readable and easier to solve for users.

Example call using all parameters: VerificationCaptcha.GenerateCaptchaContent(IncludeNumbers: false, TypefaceFamilyName: "Verdana", CaptchaLength: 10, JpegQualityLevel: 80, ReduceRandomCharacters: true);

Here is an example of how you can use BlazorVerificationCaptcha in your Blazor component:

<VerificationCaptcha />

@code {

    private string ExampleVariable;

    protected override Task OnInitializedAsync()
    {
        ExampleVariable = VerificationCaptcha.GenerateCaptchaContent();
        return base.OnInitializedAsync();
    }
}

Example (Generator)

Here is an example of how you can use the generator without the component, to get the values and display it by yourself

<p>@ExampleVariable.Text</p>
<p>@ExampleVariable.Image</p>

@code {

    private (string Image, string Text) ExampleVariable;

    protected override Task OnInitializedAsync()
    {
        ExampleVariable = CaptchaGenerator.GenerateCaptcha();
        return base.OnInitializedAsync();
    }
}

This example doesn't show how to handle checking if the captcha is correct but you have the ExampleVariable, so you can easily just do if(ExampleVariable.Equals(ExampleInputVariable, StringComparison.InvariantCulture)).

FAQ

Notes on Linux

Should the captcha only show colored backgrounds without any content, this can be resolved by installing the aforementioned dependencies.

This application is intended to be able to run on a Linux environment (for ASP-Hosting etc.). Please take note of the following important considerations:

  1. Dependencies: In order to ensure smooth functionality, it is essential to install the following dependencies on your Linux system:

    • fontconfig
    • freetype
    • freetype-devel
    • fontconfig-devel
    • libstdc++
  2. Installation: On CentOS I installed the required packages by executing the following command in your terminal: yum install fontconfig freetype freetype-devel fontconfig-devel libstdc++

What do I have to be aware of?

The image is displayed as base64, I'm working on another way propably JavaScript.

License

Software: BlazorVerificationCaptcha

License: GNU General Public License v3.0

Roadmap

  • Implement an alternative way to display the captcha image, besides base64 (even tho I don't think there is an better way).
  • Maybe implement features for barrier free things like text2speech etc.
Product Compatible and additional computed target framework versions.
.NET 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 was computed.  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. 
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
0.1.2 223 8/20/2023
0.1.1 163 6/14/2023
0.1.0 156 6/13/2023

This update introduces customizable CAPTCHA length, dynamic image dimensions based on length, adjustable image quality, and various refinements for improved functionality.