### Install SixLaborsCaptcha.Core via dotnet CLI Source: https://github.com/aliasadidev/sixlaborscaptcha/blob/master/README.md Run this command in the terminal to install the SixLaborsCaptcha.Core NuGet package version 1.0.0. ```bash > dotnet add package SixLaborsCaptcha.Core --version 1.0.0 ``` -------------------------------- ### Install SixLaborsCaptcha.Mvc.Core via dotnet CLI Source: https://github.com/aliasadidev/sixlaborscaptcha/blob/master/README.md Run this command in the terminal to install the SixLaborsCaptcha.Mvc.Core NuGet package version 1.0.0 for ASP.NET Core MVC. ```bash > dotnet add package SixLaborsCaptcha.Mvc.Core --version 1.0.0 ``` -------------------------------- ### Download and install Marlboro font on Linux Source: https://github.com/aliasadidev/sixlaborscaptcha/blob/master/README.md Commands to download, extract, and install the Marlboro font to ~/.fonts/ for use with the captcha generator on Linux. Also lists alternative font paths. ```bash 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. ``` -------------------------------- ### Create GetCaptchaImage action to generate captcha image Source: https://github.com/aliasadidev/sixlaborscaptcha/blob/master/README.md Creates an HTTP GET action that uses ISixLaborsCaptchaModule to generate a captcha image and returns it as a FileResult. The action is routed via [Route("[action]")]. ```csharp using SixLaborsCaptcha.Core; ... [HttpGet] [Route("[action]")] public FileResult GetCaptchaImage([FromServices] ISixLaborsCaptchaModule sixLaborsCaptcha) { string key = Extensions.GetUniqueKey(6); var imgText = sixLaborsCaptcha.Generate(key); return File(imgText, "Image/Png"); } ``` -------------------------------- ### Register AddSixLabCaptcha in ConfigureServices Source: https://github.com/aliasadidev/sixlaborscaptcha/blob/master/README.md In the ConfigureServices method of Startup.cs, register the AddSixLabCaptcha generator with options to set DrawLines to 4. ```csharp using SixLaborsCaptcha.Mvc.Core; ... public void ConfigureServices(IServiceCollection services) { services.AddSixLabCaptcha(x => { x.DrawLines = 4; }); } ``` -------------------------------- ### Generate captcha image in console app with SixLaborsCaptchaModule Source: https://github.com/aliasadidev/sixlaborscaptcha/blob/master/README.md Creates a SixLaborsCaptchaModule with options for drawing lines and text color, generates a unique key, and writes the captcha image to a file. Uses Extensions.GetUniqueKey(6) for the key. ```csharp 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 = Extensions.GetUniqueKey(6); var result = slc.Generate(key); File.WriteAllBytes($"six-labors-captcha.png", result); } } } ``` -------------------------------- ### Configure AddSixLabCaptcha with custom font family Source: https://github.com/aliasadidev/sixlaborscaptcha/blob/master/README.md Configures the AddSixLabCaptcha service to use the 'Marlboro' font family, which is required when running on Linux with the downloaded font. ```csharp services.AddSixLabCaptcha(x => { x.FontFamilies = new string[] { "Marlboro" }; }); ``` -------------------------------- ### Display captcha images in Razor view Source: https://github.com/aliasadidev/sixlaborscaptcha/blob/master/README.md HTML view that displays four captcha images by calling the GetCaptchaImage action with different query string parameters (?v1, ?v2, ?v3, ?v4). ```html