SixLaborsCaptcha.Mvc.Core 0.2.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package SixLaborsCaptcha.Mvc.Core --version 0.2.1                
NuGet\Install-Package SixLaborsCaptcha.Mvc.Core -Version 0.2.1                
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="SixLaborsCaptcha.Mvc.Core" Version="0.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SixLaborsCaptcha.Mvc.Core --version 0.2.1                
#r "nuget: SixLaborsCaptcha.Mvc.Core, 0.2.1"                
#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 SixLaborsCaptcha.Mvc.Core as a Cake Addin
#addin nuget:?package=SixLaborsCaptcha.Mvc.Core&version=0.2.1

// Install SixLaborsCaptcha.Mvc.Core as a Cake Tool
#tool nuget:?package=SixLaborsCaptcha.Mvc.Core&version=0.2.1                

SixLaborsCaptcha

SixLaborsCaptcha is a simple cross-platform NuGet package for generating image captcha.

Features

  • Simple & Cross-Platform
  • Compatible with Linux and Windows
  • Compatible with Docker images based on Linux 😃

What's New

Version 0.2.1 - Jul 22, 2022

Add
  • Add BackgroundColor option
Fix
  • Fixed a typo (Extentions renamed to Extensions)

Version 0.2.0 - Apr 22, 2022

Change
  • Upgrade SixLabors.ImageSharp to 2.1.1
  • âš  WARNING: This version incompatible with the previous version of SixLabors.ImageSharp 1.0.0+

Version 0.1.5 - Mar 30, 2022

Fix
  • Update readme file

Version 0.1.4 - Mar 30, 2022

Fix
  • Use DrawLinesColor instead of TextColor in creating random lines (#2 by @NK201)

Version 0.1.3 - Oct 8, 2021

Add
  • Add NoiseRateColor/NoiseRate options
  • Add MinLineThickness/MaxLineThickness options
Change
  • Improve the rendering speed
  • Improve the captcha image security

Packages

Package Description
SixLaborsCaptcha.Core Using for ConsoleApp, WebAPI, WinForms, and etc..
SixLaborsCaptcha.Mvc.Core Using for ASP.NET MVC Core and ASP.NET Web API Core

SixLaborsCaptchaOptions

Property Description
FontFamilies Characters fonts, default is "Arial", "Verdana", "Times New Roman"
TextColor Characters colors, default is { Color.Blue, Color.Black, Color.Black, Color.Brown, Color.Gray, Color.Green }
DrawLinesColor Line colors, default is { Color.Blue, Color.Black, Color.Black, Color.Brown, Color.Gray, Color.Green }
Width Width of image box, default is 180
Height Height of image box, default is 50
FontSize Font size, default is 29
FontStyle Font Style: Regular,Bold,Italic,BoldItalic
EncoderType Result file formant: Jpeg,Png
DrawLines Draw the random lines, default is 5
MaxRotationDegrees Rotation degrees, default is 5
MinLineThickness Min Line Thickness, default is 0.7f
MaxLineThickness Max Line Thickness, default is 2.0f
NoiseRate Noise Rate, default is 800
NoiseRateColor Noise colors, default is { Color.Gray }
BackgroundColor Background colors, default is { Color.White }

FontFamilies Option: Notice: This default fonts working only on Windows, if you want to run it on Linux you have to use the Linux fonts

Install via CLI

To install SixLaborsCaptcha.Core, run the following command in the terminal:

> dotnet add package SixLaborsCaptcha.Core --version 0.2.1

Usage:

using SixLaborsCaptcha.Core;
using SixLabors.ImageSharp;
using System.IO;

namespace ConsoleAppSample
{
	class Program
	{
		static void Main(string[] args)
		{
			var slc = new SixLaborsCaptchaModule(new SixLaborsCaptchaOptions
			{
				DrawLines = 7,
				TextColor = new Color[] { Color.Blue, Color.Black },
			});

			var key = Extentions.GetUniqueKey(6);
			var result = slc.Generate(key);
			File.WriteAllBytes($"six-labors-captcha.png", result);
		}
	}
}

result

To install SixLaborsCaptcha.Mvc.Core for ASP.NET Core MVC, run the following command in the Terminal:

> dotnet add package SixLaborsCaptcha.Mvc.Core --version 0.2.1

Usage:

  1. In the ConfigureServices method of Startup.cs, register the AddSixLabCaptcha generator
using SixLaborsCaptcha.Mvc.Core;
...
		public void ConfigureServices(IServiceCollection services)
		{
			services.AddSixLabCaptcha(x =>
			{
				x.DrawLines = 4;
			});
		}
...
  1. Create an action to generate image
using SixLaborsCaptcha.Core;
...

[HttpGet]
[Route("[action]")]
public FileResult GetCaptchaImage([FromServices] ISixLaborsCaptchaModule sixLaborsCaptcha)
{
	string key = Extentions.GetUniqueKey(6);
	var imgText = sixLaborsCaptcha.Generate(key);
	return File(imgText, "Image/Png");
}

...
  1. Get the image from action
<div class="text-center">
	<h1 class="display-4">Welcome to SixLaborsCaptcha</h1>
	<img src='@Url.Action("GetCaptchaImage","Home")?v1' />
	<br />
	<img src='@Url.Action("GetCaptchaImage","Home")?v2' />
	<br />
	<img src='@Url.Action("GetCaptchaImage","Home")?v3' />
	<br />
	<img src='@Url.Action("GetCaptchaImage","Home")?v4' />
</div>

result result result result

Run asp.net core mvc app on Linux os:

  1. Download a font (also, you can use the system fonts and don't needs to do this step)
wget -O ~/Downloads/marlboro.zip https://www.1001freefonts.com/d/3761/marlboro.zip
unzip -p ~/Downloads/marlboro.zip Marlboro.ttf > ~/Downloads/Marlboro.ttf
rm ~/Downloads/marlboro.zip
cp ~/Downloads/Marlboro.ttf ~/.fonts/
# other paths
# ~/.fonts/ - for your own fonts.
# /usr/local/share/fonts/ - system-wide, user installed fonts.
# /usr/share/fonts/ - system's font location.
  1. Config the serivce

services.AddSixLabCaptcha(x => {
			   x.FontFamilies = new string[] { "Marlboro" };
		         });

linux-result

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.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 was computed. 
.NET Framework net461 was computed.  net462 was computed.  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 (1)

Showing the top 1 NuGet packages that depend on SixLaborsCaptcha.Mvc.Core:

Package Downloads
App.Assets.Froshoo.V1

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 6,632 3/13/2024
0.2.2 36,633 9/26/2022
0.2.1 1,277 7/22/2022
0.2.0 5,782 4/22/2022
0.1.5 496 3/30/2022
0.1.4 422 3/30/2022
0.1.3 1,476 10/8/2021
0.1.2 4,791 9/20/2020
0.1.1 436 9/20/2020
0.1.0 551 9/19/2020