├── src ├── Captcha.Net │ ├── EncoderTypes.cs │ ├── ICaptchaModule.cs │ ├── Properties │ │ └── launchSettings.json │ ├── CaptchaResult.cs │ ├── CaptchaGenerator.cs │ ├── Captcha.Net.csproj │ ├── Extensions.cs │ ├── CaptchaOptions.cs │ └── Captcha.cs ├── Captcha.Net.Sample │ ├── Properties │ │ └── launchSettings.json │ ├── Captcha.Net.Sample.csproj │ ├── Dockerfile │ └── Program.cs ├── .dockerignore ├── Captcha.Net.Test │ ├── Captcha.Net.Test.csproj │ ├── IntegrationTests │ │ └── CaptchaGeneratorTest.cs │ └── UnitTests │ │ ├── ExtensionsTest.cs │ │ └── CaptchaTest.cs └── Captcha.Net.sln ├── load test result ├── single thread - windows 11.png └── single thread - docker linux ubuntu 22.png ├── .github └── workflows │ ├── dotnet-ubuntu.yml │ └── dotnet-windows.yml ├── LICENSE ├── README.md └── .gitignore /src/Captcha.Net/EncoderTypes.cs: -------------------------------------------------------------------------------- 1 | namespace Captcha.Net; 2 | 3 | public enum EncoderTypes 4 | { 5 | Jpeg, 6 | Png, 7 | } 8 | -------------------------------------------------------------------------------- /load test result/single thread - windows 11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezzad/CaptchaGenerator/HEAD/load test result/single thread - windows 11.png -------------------------------------------------------------------------------- /src/Captcha.Net/ICaptchaModule.cs: -------------------------------------------------------------------------------- 1 | namespace Captcha.Net; 2 | 3 | public interface ICaptchaModule 4 | { 5 | byte[] Generate(string text); 6 | } 7 | -------------------------------------------------------------------------------- /load test result/single thread - docker linux ubuntu 22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bezzad/CaptchaGenerator/HEAD/load test result/single thread - docker linux ubuntu 22.png -------------------------------------------------------------------------------- /src/Captcha.Net/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "CaptchaGeneratorApp": { 4 | "commandName": "Project" 5 | }, 6 | "WSL": { 7 | "commandName": "WSL2", 8 | "distributionName": "" 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /src/Captcha.Net.Sample/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "CaptchaGenerator.Sample": { 4 | "commandName": "Project" 5 | }, 6 | "WSL": { 7 | "commandName": "WSL2", 8 | "distributionName": "" 9 | }, 10 | "Docker": { 11 | "commandName": "Docker" 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /src/.dockerignore: -------------------------------------------------------------------------------- 1 | **/.classpath 2 | **/.dockerignore 3 | **/.env 4 | **/.git 5 | **/.gitignore 6 | **/.project 7 | **/.settings 8 | **/.toolstarget 9 | **/.vs 10 | **/.vscode 11 | **/*.*proj.user 12 | **/*.dbmdl 13 | **/*.jfm 14 | **/azds.yaml 15 | **/bin 16 | **/charts 17 | **/docker-compose* 18 | **/Dockerfile* 19 | **/node_modules 20 | **/npm-debug.log 21 | **/obj 22 | **/secrets.dev.yaml 23 | **/values.dev.yaml 24 | LICENSE 25 | README.md -------------------------------------------------------------------------------- /src/Captcha.Net/CaptchaResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Captcha.Net; 4 | 5 | public class CaptchaResult 6 | { 7 | public string CaptchaCode { get; set; } 8 | public byte[] CaptchaByteData { get; set; } 9 | public string CaptchBase64Data 10 | { 11 | get => Convert.ToBase64String(CaptchaByteData); 12 | set => CaptchaByteData = Convert.FromBase64String(value); 13 | } 14 | public DateTime Timestamp { get; set; } 15 | } 16 | -------------------------------------------------------------------------------- /src/Captcha.Net.Sample/Captcha.Net.Sample.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exe 5 | net6.0 6 | enable 7 | enable 8 | Linux 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/Captcha.Net.Sample/Dockerfile: -------------------------------------------------------------------------------- 1 | # FROM docker.mofid.dev/mofidonline/dotnet/aspnet-webapi-libgdplus:6.0 2 | FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base 3 | 4 | # Install the fontconfig package 5 | RUN apt-get update; apt-get install -y fontconfig fonts-liberation 6 | 7 | # Update the font cache 8 | RUN fc-cache -f -v 9 | 10 | WORKDIR /app 11 | 12 | FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build 13 | 14 | WORKDIR /src 15 | COPY ["Captcha.Net.Sample/Captcha.Net.Sample.csproj", "Captcha.Net.Sample/"] 16 | COPY ["Captcha.Net/Captcha.Net.csproj", "Captcha.Net/"] 17 | RUN dotnet restore "Captcha.Net.Sample/Captcha.Net.Sample.csproj" 18 | COPY . . 19 | WORKDIR "/src/Captcha.Net.Sample" 20 | RUN dotnet build "Captcha.Net.Sample.csproj" -c Release -o /app/build 21 | 22 | FROM build AS publish 23 | RUN dotnet publish "Captcha.Net.Sample.csproj" -c Release -o /app/publish /p:UseAppHost=false 24 | 25 | FROM base AS final 26 | WORKDIR /app 27 | COPY --from=publish /app/publish . 28 | ENTRYPOINT ["dotnet", "Captcha.Net.Sample.dll"] -------------------------------------------------------------------------------- /src/Captcha.Net.Test/Captcha.Net.Test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net6.0 5 | disable 6 | enable 7 | 8 | false 9 | 10 | 11 | 12 | 13 | 14 | 15 | runtime; build; native; contentfiles; analyzers; buildtransitive 16 | all 17 | 18 | 19 | runtime; build; native; contentfiles; analyzers; buildtransitive 20 | all 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-ubuntu.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a .NET project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net 3 | 4 | name: .NET Ubuntu x64 5 | 6 | on: [push] 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v3 14 | - name: Setup .NET 6.0.x 15 | uses: actions/setup-dotnet@v3 16 | with: 17 | dotnet-version: 6.0.x 18 | 19 | - name: Restore Captcha.Net dependencies 20 | run: dotnet restore ./src/Captcha.Net/Captcha.Net.csproj 21 | 22 | - name: Build Captcha.Net 23 | run: dotnet build ./src/Captcha.Net/Captcha.Net.csproj --no-restore 24 | 25 | - name: Restore Captcha.Net.Test Dependencies 26 | run: dotnet restore ./src/Captcha.Net.Test/Captcha.Net.Test.csproj 27 | 28 | - name: Build Captcha.Net.Test Project 29 | run: dotnet build ./src/Captcha.Net.Test/Captcha.Net.Test.csproj --no-restore 30 | 31 | - name: Run Tests 32 | run: dotnet test ./src/Captcha.Net.Test/Captcha.Net.Test.csproj --no-build --verbosity normal 33 | -------------------------------------------------------------------------------- /.github/workflows/dotnet-windows.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a .NET project 2 | # For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net 3 | 4 | name: .NET Windows x64 5 | 6 | on: [push] 7 | 8 | jobs: 9 | build: 10 | runs-on: windows-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v3 14 | - name: Setup .NET 6.0.x 15 | uses: actions/setup-dotnet@v3 16 | with: 17 | dotnet-version: 6.0.x 18 | 19 | - name: Restore Captcha.Net dependencies 20 | run: dotnet restore ./src/Captcha.Net/Captcha.Net.csproj 21 | 22 | - name: Build Captcha.Net 23 | run: dotnet build ./src/Captcha.Net/Captcha.Net.csproj --no-restore 24 | 25 | - name: Restore Captcha.Net.Test Dependencies 26 | run: dotnet restore ./src/Captcha.Net.Test/Captcha.Net.Test.csproj 27 | 28 | - name: Build Captcha.Net.Test Project 29 | run: dotnet build ./src/Captcha.Net.Test/Captcha.Net.Test.csproj --no-restore 30 | 31 | - name: Run Tests 32 | run: dotnet test ./src/Captcha.Net.Test/Captcha.Net.Test.csproj --no-build --verbosity normal 33 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Behzad Khosravifar 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/Captcha.Net/CaptchaGenerator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | 4 | namespace Captcha.Net; 5 | 6 | public class CaptchaGenerator 7 | { 8 | private static char[] CodeLetters = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 9 | private static ConcurrentDictionary CaptchaKeeper = new ConcurrentDictionary(); 10 | 11 | public string GenerateCaptchaCode(int keyDigit = 4) 12 | { 13 | return Extensions.GetUniqueKey(keyDigit, CodeLetters); 14 | } 15 | 16 | public CaptchaResult GenerateCaptchaImage(ushort width, ushort height, string captchaCode) 17 | { 18 | var key = $"{width}w_{height}h_{captchaCode.Length}d"; 19 | var captcha = CaptchaKeeper.GetOrAdd(key, k => 20 | new Captcha(new CaptchaOptions 21 | { 22 | Width = width, 23 | Height = height, 24 | MaxRotationDegrees = 15, 25 | RotationDegree = 7, 26 | NoiseRate = 50, 27 | DrawLines = 4, 28 | FontSize = GetFontSize(width, captchaCode.Length), 29 | EncoderType = EncoderTypes.Jpeg 30 | })); 31 | 32 | var captchaCodeBytes = captcha.Generate(captchaCode); 33 | 34 | return new CaptchaResult 35 | { 36 | CaptchaCode = captchaCode, 37 | CaptchaByteData = captchaCodeBytes, 38 | Timestamp = DateTime.Now 39 | }; 40 | } 41 | 42 | private byte GetFontSize(int imageWidth, int captchCodeLength) 43 | { 44 | var averageSize = imageWidth / captchCodeLength * 1.2; 45 | return Convert.ToByte(averageSize); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/Captcha.Net/Captcha.Net.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Library 5 | net6.0 6 | true 7 | True 8 | Captcha.Net 9 | Captcha.Net 10 | 1.2.1 11 | Bezzad 12 | CAPTCHA Generator with .Net 6.0 13 | 2023 14 | https://github.com/bezzad/CaptchaGenerator 15 | README.md 16 | https://github.com/bezzad/CaptchaGenerator 17 | git 18 | Captcha; image-generator; captcha-generator; recaptcha 19 | Improved performance of Captcha 20 | LICENSE 21 | True 22 | $(FileVersion) 23 | 24 | 25 | 26 | 27 | True 28 | \ 29 | 30 | 31 | True 32 | \ 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /src/Captcha.Net.Sample/Program.cs: -------------------------------------------------------------------------------- 1 | using Captcha.Net; 2 | using System.Diagnostics; 3 | 4 | var captchaGenerator = new CaptchaGenerator(); 5 | var currentDirectory = Directory.CreateDirectory("captcha"); 6 | var count = 10000; 7 | var times = new List(count); 8 | var stopWatch = new Stopwatch(); 9 | 10 | for (int i = 0; i < count; i++) 11 | { 12 | stopWatch.Restart(); 13 | var key = captchaGenerator.GenerateCaptchaCode(); 14 | var result = captchaGenerator.GenerateCaptchaImage(145, 56, key); 15 | stopWatch.Stop(); 16 | Console.WriteLine($"Captcha {i}: \n"); 17 | Console.WriteLine(result.CaptchBase64Data); 18 | Console.WriteLine(); 19 | times.Add(stopWatch.ElapsedMilliseconds); 20 | File.WriteAllBytes($"{currentDirectory.FullName}/captcha-{i}.jpg", result.CaptchaByteData); 21 | } 22 | 23 | var maxDuration = times.Max(); 24 | Console.WriteLine($"Duration: Max({maxDuration}ms), Min({times.Min()}ms), Average({times.Average()}ms)"); 25 | for (int i = 1, q = 1; i < maxDuration + q; i += q) 26 | { 27 | var timeCount = times.Count(t => t <= i && t > i - q); 28 | 29 | if (timeCount != 0) 30 | { 31 | Console.WriteLine($"Time[{i - q}ms ~ {i}ms]: {timeCount}"); 32 | } 33 | 34 | if (i == 10) 35 | q = 10; 36 | else if (i == 100) 37 | q = 100; 38 | else if (i == 1000) 39 | q = 1000; 40 | } 41 | 42 | try 43 | { 44 | // open the directory after completion 45 | if (OperatingSystem.IsWindows()) 46 | { 47 | Process.Start("explorer.exe", currentDirectory.FullName); 48 | } 49 | else if (OperatingSystem.IsLinux()) 50 | { 51 | // Start a new process to open the folder 52 | Process.Start("xdg-open", currentDirectory.FullName); 53 | } 54 | } 55 | catch { } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![.NET Windows x64](https://github.com/bezzad/CaptchaGenerator/actions/workflows/dotnet-windows.yml/badge.svg)](https://github.com/bezzad/CaptchaGenerator/actions/workflows/dotnet-windows.yml) 2 | [![.NET Ubuntu x64](https://github.com/bezzad/CaptchaGenerator/actions/workflows/dotnet-ubuntu.yml/badge.svg)](https://github.com/bezzad/CaptchaGenerator/actions/workflows/dotnet-ubuntu.yml) 3 | [![NuGet](https://img.shields.io/nuget/dt/Captcha.Net.svg)](https://www.nuget.org/packages/Captcha.Net) 4 | [![NuGet](https://img.shields.io/nuget/vpre/Captcha.Net.svg)](https://www.nuget.org/packages/Captcha.Net) 5 | [![License](https://img.shields.io/github/license/bezzad/CaptchaGenerator.svg)](https://github.com/bezzad/CaptchaGenerator/blob/master/LICENSE) 6 | [![Generic badge](https://img.shields.io/badge/support-.Net_6-blue.svg)](https://github.com/bezzad/CaptchaGenerator) 7 | 8 | # Captcha Generator .Net 9 | Captcha Generator is a simple cross-platform library for generating image captcha. 10 | 11 | ## Features 12 | 13 | - Simple & Cross-Platform 14 | - Compatible with Linux and Windows 15 | - Compatible with Docker images based on Linux :) 16 | 17 | ## Installing via [NuGet](https://www.nuget.org/packages/Downloader) 18 | 19 | PM> Install-Package Captcha.Net 20 | 21 | ## Installing via the .NET Core command line interface 22 | 23 | dotnet add package Captcha.Net 24 | 25 | ## Usage: 26 | ```csharp 27 | using Captcha.Net; 28 | 29 | namespace ConsoleAppSample 30 | { 31 | class Program 32 | { 33 | static void Main(string[] args) 34 | { 35 | var captchaGenerator = new CaptchaGenerator(); 36 | var key = captchaGenerator.GenerateCaptchaCode(); 37 | var result = captchaGenerator.GenerateCaptchaImage(200, 100, key); 38 | File.WriteAllBytes($"captcha.jpg", result.CaptchaByteData); 39 | 40 | Console.WriteLine(result.CaptchBase64Data); 41 | } 42 | } 43 | } 44 | 45 | ``` -------------------------------------------------------------------------------- /src/Captcha.Net.Test/IntegrationTests/CaptchaGeneratorTest.cs: -------------------------------------------------------------------------------- 1 | using SixLabors.ImageSharp; 2 | using SixLabors.ImageSharp.Advanced; 3 | using SixLabors.ImageSharp.PixelFormats; 4 | using System.Linq; 5 | using Xunit; 6 | 7 | namespace Captcha.Net.Test.IntegrationTests; 8 | 9 | public class CaptchaGeneratorTest 10 | { 11 | [Fact] 12 | public void GenerateCaptchaCodeWithPureNumericalLettersTest() 13 | { 14 | // arrange 15 | var codeLetters = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; 16 | var generator = new CaptchaGenerator(); 17 | 18 | // act 19 | var code = generator.GenerateCaptchaCode(8); 20 | 21 | // assert 22 | Assert.Equal(8, code.Length); 23 | Assert.True(code.Select(k => codeLetters.Contains(k)).All(i => i)); 24 | } 25 | 26 | [Fact] 27 | public void GenerateCaptchaImageTest() 28 | { 29 | // arrange 30 | ushort width = 100; 31 | ushort height = 50; 32 | var jpegWhiteBalanceRatio = 0.99; // 99% like white color 33 | var code = "012340"; 34 | var generator = new CaptchaGenerator(); 35 | var backgroundHistogram = 0; 36 | 37 | // act 38 | var captcha = generator.GenerateCaptchaImage(width, height, code); 39 | var image = Image.Load(captcha.CaptchaByteData); 40 | var pixels = image.GetPixelMemoryGroup().SelectMany(g => g.ToArray()); 41 | foreach (var pixel in pixels) 42 | { 43 | if (pixel.Rgba >= Color.White.ToPixel().Rgba * jpegWhiteBalanceRatio) 44 | backgroundHistogram++; 45 | } 46 | 47 | // assert 48 | Assert.NotNull(captcha); 49 | Assert.NotNull(captcha.CaptchaByteData); 50 | Assert.NotNull(captcha.CaptchBase64Data); 51 | Assert.Equal(code, captcha.CaptchaCode); 52 | Assert.Equal(width, image.Width); 53 | Assert.Equal(height, image.Height); 54 | Assert.True(width * height * 0.2 < backgroundHistogram); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Captcha.Net/Extensions.cs: -------------------------------------------------------------------------------- 1 | using SixLabors.ImageSharp.Formats; 2 | using SixLabors.ImageSharp.Formats.Jpeg; 3 | using SixLabors.ImageSharp.Formats.Png; 4 | using System; 5 | using System.Security.Cryptography; 6 | using System.Text; 7 | 8 | namespace Captcha.Net; 9 | 10 | public static class Extensions 11 | { 12 | private static Random Rand = new Random(DateTime.Now.GetHashCode()); 13 | 14 | private static readonly char[] Chars = "abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVXYZW23456789".ToCharArray(); 15 | 16 | public static IImageEncoder GetEncoder(EncoderTypes encoderType) 17 | { 18 | IImageEncoder encoder; 19 | switch (encoderType) 20 | { 21 | case EncoderTypes.Png: 22 | encoder = new PngEncoder(); 23 | break; 24 | case EncoderTypes.Jpeg: 25 | encoder = new JpegEncoder(); 26 | break; 27 | default: 28 | throw new ArgumentException($"Encoder '{encoderType}' not found!"); 29 | }; 30 | return encoder; 31 | } 32 | 33 | public static string GetUniqueKey(int size) 34 | { 35 | return GetUniqueKey(size, Chars); 36 | } 37 | 38 | public static string GetUniqueKey(int size, char[] chars) 39 | { 40 | byte[] data = new byte[4 * size]; 41 | RandomNumberGenerator.Fill(data); 42 | StringBuilder result = new StringBuilder(size); 43 | for (int i = 0; i < size; i++) 44 | { 45 | var rnd = BitConverter.ToUInt32(data, i * 4); 46 | var idx = rnd % chars.Length; 47 | result.Append(chars[idx]); 48 | } 49 | 50 | return result.ToString(); 51 | } 52 | 53 | public static float GenerateNextFloat(double min = double.MinValue, double max = double.MaxValue) 54 | { 55 | double range = max - min; 56 | double sample = Rand.NextDouble(); 57 | double scaled = sample * range + min; 58 | float result = (float)scaled; 59 | return result; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/Captcha.Net.Test/UnitTests/ExtensionsTest.cs: -------------------------------------------------------------------------------- 1 | using SixLabors.ImageSharp.Formats.Jpeg; 2 | using SixLabors.ImageSharp.Formats.Png; 3 | using System.Linq; 4 | using Xunit; 5 | 6 | namespace Captcha.Net.Test.UnitTests; 7 | 8 | public class ExtensionsTest 9 | { 10 | [Fact] 11 | public void GetEncoderOfPngTest() 12 | { 13 | // arrange 14 | var encoderType = EncoderTypes.Png; 15 | 16 | // act 17 | var encoder = Extensions.GetEncoder(encoderType); 18 | 19 | // assert 20 | Assert.IsType(encoder); 21 | } 22 | 23 | [Fact] 24 | public void GetEncoderOfJpegTest() 25 | { 26 | // arrange 27 | var encoderType = EncoderTypes.Jpeg; 28 | 29 | // act 30 | var encoder = Extensions.GetEncoder(encoderType); 31 | 32 | // assert 33 | Assert.IsType(encoder); 34 | } 35 | 36 | [Fact] 37 | public void GetUniqueKeyTest() 38 | { 39 | // arrange 40 | var len = 6; 41 | 42 | // action 43 | var key = Extensions.GetUniqueKey(len); 44 | 45 | // assert 46 | Assert.NotNull(key); 47 | Assert.Equal(len, key.Length); 48 | } 49 | 50 | [Fact] 51 | public void GetUniqueKeyWithSpecificCharsTest() 52 | { 53 | // arrange 54 | var len = 8; 55 | var chars = new char[] { '1', '2', '3', '4', '5' }; 56 | 57 | // action 58 | var key = Extensions.GetUniqueKey(len, chars); 59 | 60 | // assert 61 | Assert.NotNull(key); 62 | Assert.Equal(len, key.Length); 63 | Assert.True(key.Select(k => chars.Contains(k)).All(i => i)); 64 | } 65 | 66 | [Fact] 67 | public void GenerateNextFloatTest() 68 | { 69 | // arrange 70 | var min = 0; 71 | var max = 1; 72 | 73 | // action 74 | var randomNum = Extensions.GenerateNextFloat(min, max); 75 | 76 | // assert 77 | Assert.True(randomNum >= min, $"Random number is: {randomNum}"); 78 | Assert.True(randomNum <= max, $"Random number is: {randomNum}"); 79 | } 80 | } -------------------------------------------------------------------------------- /src/Captcha.Net/CaptchaOptions.cs: -------------------------------------------------------------------------------- 1 | using SixLabors.Fonts; 2 | using SixLabors.ImageSharp; 3 | using SixLabors.ImageSharp.Formats; 4 | using System.Runtime.InteropServices; 5 | 6 | namespace Captcha.Net; 7 | 8 | public class CaptchaOptions 9 | { 10 | /// 11 | /// Default fonts are "Arial", "Verdana", "Times New Roman" in Windows 12 | /// Linux guys have to set thier own fonts :) 13 | /// 14 | public string[] FontFamilies { get; set; } 15 | public Color[] TextColor { get; set; } = new Color[] { Color.Blue, Color.Black, Color.Black, Color.DarkGray, Color.Brown, Color.Gray, Color.Gray, Color.Green, Color.SlateGray }; 16 | public Color[] DrawLinesColor { get; set; } = new Color[] { Color.Blue, Color.Black, Color.Red, Color.Brown, Color.Gray, Color.Green, Color.SlateGray }; 17 | public float MinLineThickness { get; set; } = 0.7f; 18 | public float MaxLineThickness { get; set; } = 2.0f; 19 | public ushort Width { get; set; } = 180; 20 | public ushort Height { get; set; } = 50; 21 | public ushort NoiseRate { get; set; } = 100; 22 | public Color[] NoiseRateColor { get; set; } = new Color[] { Color.Gray, Color.Black, Color.Red }; 23 | public int FontSize { get; set; } = 29; 24 | public FontStyle FontStyle { get; set; } = FontStyle.Regular; 25 | public EncoderTypes EncoderType { get; set; } = EncoderTypes.Jpeg; 26 | public IImageEncoder Encoder => Extensions.GetEncoder(EncoderType); 27 | public int DrawLines { get; set; } = 5; 28 | public int MaxRotationDegrees { get; set; } = 5; 29 | public Color[] BackgroundColor { get; set; } = new Color[] { Color.White }; 30 | public float? RotationDegree { get; set; } = 3; 31 | 32 | public CaptchaOptions() 33 | { 34 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) 35 | FontFamilies = new string[] { "DejaVu Serif", "DejaVu Sans Mono", "Liberation Sans" }; 36 | else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) 37 | FontFamilies = new string[] { "San Francisco", "Helvetica" }; 38 | else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) 39 | FontFamilies = new string[] { "Microsoft Sans Serif", "Arial", "Verdana", "Times New Roman" }; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Captcha.Net.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.4.33213.308 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Captcha.Net.Sample", "Captcha.Net.Sample\Captcha.Net.Sample.csproj", "{8676D400-3F18-419F-A9F1-4ECF9FC76C33}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Captcha.Net", "Captcha.Net\Captcha.Net.csproj", "{BB43C31D-B967-4FC1-B0D1-FFD56DDA528B}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Captcha.Net.Test", "Captcha.Net.Test\Captcha.Net.Test.csproj", "{AD83839A-6745-4C8D-9EAE-532325FCECF2}" 11 | EndProject 12 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution", "Solution", "{8FC30BDC-497D-4B82-A1D1-07BE3D95A1F8}" 13 | ProjectSection(SolutionItems) = preProject 14 | ..\.github\workflows\dotnet-ubuntu.yml = ..\.github\workflows\dotnet-ubuntu.yml 15 | ..\.github\workflows\dotnet-windows.yml = ..\.github\workflows\dotnet-windows.yml 16 | ..\LICENSE = ..\LICENSE 17 | ..\README.md = ..\README.md 18 | EndProjectSection 19 | EndProject 20 | Global 21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 22 | Debug|Any CPU = Debug|Any CPU 23 | Release|Any CPU = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {8676D400-3F18-419F-A9F1-4ECF9FC76C33}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {8676D400-3F18-419F-A9F1-4ECF9FC76C33}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {8676D400-3F18-419F-A9F1-4ECF9FC76C33}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {8676D400-3F18-419F-A9F1-4ECF9FC76C33}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {BB43C31D-B967-4FC1-B0D1-FFD56DDA528B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {BB43C31D-B967-4FC1-B0D1-FFD56DDA528B}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {BB43C31D-B967-4FC1-B0D1-FFD56DDA528B}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {BB43C31D-B967-4FC1-B0D1-FFD56DDA528B}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {AD83839A-6745-4C8D-9EAE-532325FCECF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {AD83839A-6745-4C8D-9EAE-532325FCECF2}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {AD83839A-6745-4C8D-9EAE-532325FCECF2}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {AD83839A-6745-4C8D-9EAE-532325FCECF2}.Release|Any CPU.Build.0 = Release|Any CPU 38 | EndGlobalSection 39 | GlobalSection(SolutionProperties) = preSolution 40 | HideSolutionNode = FALSE 41 | EndGlobalSection 42 | GlobalSection(ExtensibilityGlobals) = postSolution 43 | SolutionGuid = {088ECFD8-C6FB-493A-B86E-4B663DB51DFE} 44 | EndGlobalSection 45 | EndGlobal 46 | -------------------------------------------------------------------------------- /src/Captcha.Net.Test/UnitTests/CaptchaTest.cs: -------------------------------------------------------------------------------- 1 | using SixLabors.ImageSharp; 2 | using SixLabors.ImageSharp.Advanced; 3 | using SixLabors.ImageSharp.Drawing.Processing; 4 | using SixLabors.ImageSharp.PixelFormats; 5 | using SixLabors.ImageSharp.Processing; 6 | using SixLabors.ImageSharp.Processing.Processors.Transforms; 7 | using System; 8 | using Xunit; 9 | 10 | namespace Captcha.Net.Test.UnitTests; 11 | 12 | public class CaptchaTest : Captcha 13 | { 14 | public CaptchaTest() : base(new CaptchaOptions()) { } 15 | 16 | [Theory] 17 | [InlineData(10, 10)] 18 | [InlineData(100, 100)] 19 | [InlineData(200, 100)] 20 | [InlineData(100, 300)] 21 | public void ImageSizeTest(int width, int height) 22 | { 23 | // act 24 | using var img = new Image(width, height); 25 | 26 | // assert 27 | Assert.Equal(width, img.Width); 28 | Assert.Equal(height, img.Height); 29 | } 30 | 31 | [Theory] 32 | [InlineData(10, 10)] 33 | [InlineData(100, 100)] 34 | [InlineData(200, 100)] 35 | [InlineData(100, 300)] 36 | public void AddNoisePointTest(int width, int height) 37 | { 38 | // arrange 39 | var pixels = new Rgba32[width * height].AsSpan(); 40 | var noiseColor = Color.Black.ToPixel(); 41 | var backgroundColor = Color.White.ToPixel(); 42 | var noiseHistogram = 0; 43 | var backgroundHistogram = 0; 44 | _options.NoiseRateColor = new[] { Color.Black }; 45 | using var img = new Image(width, height); 46 | 47 | // act 48 | img.Mutate(ctx => ctx.BackgroundColor(backgroundColor)); 49 | img.Mutate(ctx => AddNoisePoint(ctx, width, height)); 50 | img.CopyPixelDataTo(pixels); 51 | foreach (var pixel in pixels) 52 | { 53 | if (pixel.Equals(noiseColor)) 54 | { 55 | noiseHistogram++; 56 | } 57 | else if (pixel.Equals(backgroundColor)) 58 | { 59 | backgroundHistogram++; 60 | } 61 | } 62 | 63 | // assert 64 | Assert.Equal(1, noiseHistogram); 65 | Assert.Equal(width * height - 1, backgroundHistogram); 66 | } 67 | 68 | [Theory] 69 | [InlineData(10, 10)] 70 | [InlineData(100, 100)] 71 | [InlineData(200, 100)] 72 | [InlineData(100, 300)] 73 | public void DrawNoiseLinesTest(int width, int height) 74 | { 75 | // arrange 76 | var pixels = new Rgba32[width * height].AsSpan(); 77 | var noiseColor = Color.Black.ToPixel(); 78 | var backgroundColor = Color.White.ToPixel(); 79 | var noiseHistogram = 0; 80 | var backgroundHistogram = 0; 81 | _options.DrawLinesColor = new[] { Color.Black }; 82 | _options.MinLineThickness = 1; 83 | _options.MaxLineThickness = 1; 84 | using var img = new Image(width, height); 85 | 86 | // act 87 | img.Mutate(ctx => ctx.BackgroundColor(backgroundColor)); 88 | img.Mutate(ctx => DrawNoiseLines(ctx, width, height)); 89 | img.CopyPixelDataTo(pixels); 90 | foreach (var pixel in pixels) 91 | { 92 | if (pixel.Equals(backgroundColor)) 93 | { 94 | backgroundHistogram++; 95 | } 96 | else 97 | { 98 | noiseHistogram++; 99 | } 100 | } 101 | 102 | // assert 103 | Assert.True(2 <= noiseHistogram, "noise histogram is less than 2"); 104 | Assert.Equal(width * height - noiseHistogram, backgroundHistogram); 105 | Assert.True(2 <= backgroundHistogram, "background histogram is less than 2"); 106 | } 107 | 108 | 109 | [Theory] 110 | [InlineData(10, 10)] 111 | [InlineData(100, 100)] 112 | public void GetRotationTest(int width, int height) 113 | { 114 | // arrange 115 | var thickness = width % 2 == 0 ? 2 : 3; 116 | var backgroundColor = Color.White.ToPixel(); 117 | var lineColor = Color.Black.ToPixel(); 118 | var middleOffsetOfWidth = width / 2; 119 | var middleOffsetOfHeight = height / 2; 120 | var originCenter = new PointF(middleOffsetOfWidth, middleOffsetOfHeight); 121 | var rotationDegrees = 90f; 122 | using var img = new Image(width, height); 123 | 124 | img.Mutate(ctx => ctx.BackgroundColor(backgroundColor)); 125 | img.Mutate(ctx => ctx.DrawLine(lineColor, thickness, new PointF[] { new PointF(middleOffsetOfWidth, 0), new PointF(middleOffsetOfWidth, height) })); 126 | 127 | // act: rotate 90 degree to a horizontal line 128 | AffineTransformBuilder rotation = GetRotation(rotationDegrees, new PointF(middleOffsetOfWidth, middleOffsetOfHeight)); 129 | img.Mutate(ctx => ctx.Transform(rotation)); // now the line is vertical 130 | var middleRowPixels = img.DangerousGetPixelRowMemory(middleOffsetOfWidth).Span; 131 | 132 | // assert 133 | foreach (var pixel in middleRowPixels) 134 | Assert.True(pixel.Rgb == lineColor.Rgb, "There is no line color!"); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/Captcha.Net/Captcha.cs: -------------------------------------------------------------------------------- 1 | using SixLabors.Fonts; 2 | using SixLabors.ImageSharp; 3 | using SixLabors.ImageSharp.Drawing.Processing; 4 | using SixLabors.ImageSharp.PixelFormats; 5 | using SixLabors.ImageSharp.Processing; 6 | using System; 7 | using System.Collections.Concurrent; 8 | using System.IO; 9 | using System.Linq; 10 | using System.Numerics; 11 | 12 | namespace Captcha.Net; 13 | 14 | public class Captcha : ICaptchaModule 15 | { 16 | protected static readonly Random Rand = new Random(DateTime.Now.GetHashCode()); 17 | protected static readonly ConcurrentDictionary> ImagesBuffer = new ConcurrentDictionary>(); 18 | protected static readonly byte CharPadding = (byte)Rand.Next(5, 10); 19 | protected static float? CharWidth; 20 | protected static float? LineThickness; 21 | protected static Color? BackgroundColor; 22 | protected static Font _font; 23 | protected static AffineTransformBuilder RotationBuilder; 24 | protected readonly CaptchaOptions _options; 25 | 26 | public Captcha(CaptchaOptions options) 27 | { 28 | _options = options; 29 | if (_font == null) 30 | { 31 | foreach (var name in _options.FontFamilies) 32 | if (SystemFonts.Collection.TryGet(name, out var fontFamily)) 33 | { 34 | _font = fontFamily.CreateFont(_options.FontSize, _options.FontStyle); 35 | break; 36 | } 37 | 38 | if (_font == null) 39 | { 40 | var fontFamily = SystemFonts.Families.FirstOrDefault(); 41 | _font = fontFamily.CreateFont(_options.FontSize, _options.FontStyle); 42 | } 43 | } 44 | 45 | BackgroundColor ??= _options.BackgroundColor[Rand.Next(0, _options.BackgroundColor.Length)]; 46 | LineThickness ??= Extensions.GenerateNextFloat(_options.MinLineThickness, _options.MaxLineThickness); 47 | CharWidth ??= TextMeasurer.MeasureAdvance("8", new TextOptions(_font)).Width; 48 | RotationBuilder ??= GetRotation(); 49 | } 50 | 51 | public byte[] Generate(string text) 52 | { 53 | using var imgText = new Image(_options.Width, _options.Height); 54 | imgText.Mutate(ctx => DrawText(ctx, _font, text)); 55 | 56 | // add the dynamic image to original image 57 | using var img = GetImageBackground(text.Length); 58 | img.Mutate(ctx => Draw(ctx, img.Width, img.Height, imgText)); 59 | 60 | using var ms = new MemoryStream(); 61 | img.Save(ms, _options.Encoder); 62 | return ms.ToArray(); 63 | } 64 | 65 | protected Image GetImageBackground(int textLength) 66 | { 67 | return ImagesBuffer.GetOrAdd(textLength, len => 68 | { 69 | var sampleText = "".PadRight(textLength, '8'); 70 | var size = (ushort)TextMeasurer.MeasureAdvance(sampleText, new TextOptions(_font)).Width; 71 | return new Image(size + 15, _options.Height); 72 | }).Clone(); 73 | } 74 | 75 | protected void DrawText(IImageProcessingContext imgContext, Font font, string text) 76 | { 77 | var position = 5f; 78 | imgContext.BackgroundColor(BackgroundColor.Value); 79 | 80 | foreach (char ch in text) 81 | { 82 | var location = new PointF(CharPadding + position, Rand.Next(6, Math.Abs(_options.Height - _options.FontSize - 5))); 83 | imgContext.DrawText(ch.ToString(), font, _options.TextColor[Rand.Next(0, _options.TextColor.Length)], location); 84 | position += CharWidth.Value; 85 | } 86 | 87 | // add rotation 88 | imgContext.Transform(RotationBuilder); 89 | } 90 | 91 | protected void Draw(IImageProcessingContext imgContext, int width, int height, Image imgText) 92 | { 93 | imgContext.BackgroundColor(_options.BackgroundColor[Rand.Next(0, _options.BackgroundColor.Length)]); 94 | imgContext.DrawImage(imgText, 0.80f); 95 | 96 | for (var i = 0; i < _options.DrawLines; i++) 97 | DrawNoiseLines(imgContext, width, height); 98 | 99 | for (var i = 0; i < _options.NoiseRate; i++) 100 | AddNoisePoint(imgContext, width, height); 101 | 102 | imgContext.Resize(_options.Width, _options.Height); 103 | } 104 | 105 | protected void AddNoisePoint(IImageProcessingContext ctx, int width, int height) 106 | { 107 | int x0 = Rand.Next(0, width); 108 | int y0 = Rand.Next(0, height); 109 | var color = _options.NoiseRateColor[Rand.Next(0, _options.NoiseRateColor.Length)]; 110 | ctx.DrawLine(color, 1F, new PointF[] { new Vector2(x0, y0), new Vector2(x0, y0) }); 111 | } 112 | 113 | protected void DrawNoiseLines(IImageProcessingContext ctx, int width, int height) 114 | { 115 | int x0 = Rand.Next(0, Rand.Next(0, Math.Min(30, width))); 116 | int y0 = Rand.Next(Math.Min(10, height), height); 117 | int x1 = Rand.Next(width - Rand.Next(0, (int)(width * 0.25)), width); 118 | int y1 = Rand.Next(0, height); 119 | var lineColor = _options.DrawLinesColor[Rand.Next(0, _options.DrawLinesColor.Length)]; 120 | ctx.DrawLine(lineColor, LineThickness.Value, new PointF[] { new PointF(x0, y0), new PointF(x1, y1) }); 121 | } 122 | 123 | protected AffineTransformBuilder GetRotation() 124 | { 125 | var width = Rand.Next(Math.Min((ushort)10u, _options.Width), _options.Width); 126 | var height = Rand.Next(Math.Min((ushort)10u, _options.Height), _options.Height); 127 | var pointF = new PointF(width, height); 128 | var rotationDegrees = _options.RotationDegree.HasValue && _options.RotationDegree <= _options.MaxRotationDegrees 129 | ? _options.RotationDegree.Value 130 | : Rand.Next(0, _options.MaxRotationDegrees); 131 | var result = GetRotation(rotationDegrees, pointF); 132 | return result; 133 | } 134 | 135 | protected AffineTransformBuilder GetRotation(float degrees, Vector2 origin) 136 | { 137 | return new AffineTransformBuilder().PrependRotationDegrees(degrees, origin); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | [Ll]ogs/ 33 | 34 | # Visual Studio 2015/2017 cache/options directory 35 | .vs/ 36 | # Uncomment if you have tasks that create the project's static files in wwwroot 37 | #wwwroot/ 38 | 39 | # Visual Studio 2017 auto generated files 40 | Generated\ Files/ 41 | 42 | # MSTest test Results 43 | [Tt]est[Rr]esult*/ 44 | [Bb]uild[Ll]og.* 45 | 46 | # NUnit 47 | *.VisualState.xml 48 | TestResult.xml 49 | nunit-*.xml 50 | 51 | # Build Results of an ATL Project 52 | [Dd]ebugPS/ 53 | [Rr]eleasePS/ 54 | dlldata.c 55 | 56 | # Benchmark Results 57 | BenchmarkDotNet.Artifacts/ 58 | 59 | # .NET Core 60 | project.lock.json 61 | project.fragment.lock.json 62 | artifacts/ 63 | 64 | # StyleCop 65 | StyleCopReport.xml 66 | 67 | # Files built by Visual Studio 68 | *_i.c 69 | *_p.c 70 | *_h.h 71 | *.ilk 72 | *.meta 73 | *.obj 74 | *.iobj 75 | *.pch 76 | *.pdb 77 | *.ipdb 78 | *.pgc 79 | *.pgd 80 | *.rsp 81 | *.sbr 82 | *.tlb 83 | *.tli 84 | *.tlh 85 | *.tmp 86 | *.tmp_proj 87 | *_wpftmp.csproj 88 | *.log 89 | *.vspscc 90 | *.vssscc 91 | .builds 92 | *.pidb 93 | *.svclog 94 | *.scc 95 | 96 | # Chutzpah Test files 97 | _Chutzpah* 98 | 99 | # Visual C++ cache files 100 | ipch/ 101 | *.aps 102 | *.ncb 103 | *.opendb 104 | *.opensdf 105 | *.sdf 106 | *.cachefile 107 | *.VC.db 108 | *.VC.VC.opendb 109 | 110 | # Visual Studio profiler 111 | *.psess 112 | *.vsp 113 | *.vspx 114 | *.sap 115 | 116 | # Visual Studio Trace Files 117 | *.e2e 118 | 119 | # TFS 2012 Local Workspace 120 | $tf/ 121 | 122 | # Guidance Automation Toolkit 123 | *.gpState 124 | 125 | # ReSharper is a .NET coding add-in 126 | _ReSharper*/ 127 | *.[Rr]e[Ss]harper 128 | *.DotSettings.user 129 | 130 | # TeamCity is a build add-in 131 | _TeamCity* 132 | 133 | # DotCover is a Code Coverage Tool 134 | *.dotCover 135 | 136 | # AxoCover is a Code Coverage Tool 137 | .axoCover/* 138 | !.axoCover/settings.json 139 | 140 | # Visual Studio code coverage results 141 | *.coverage 142 | *.coveragexml 143 | 144 | # NCrunch 145 | _NCrunch_* 146 | .*crunch*.local.xml 147 | nCrunchTemp_* 148 | 149 | # MightyMoose 150 | *.mm.* 151 | AutoTest.Net/ 152 | 153 | # Web workbench (sass) 154 | .sass-cache/ 155 | 156 | # Installshield output folder 157 | [Ee]xpress/ 158 | 159 | # DocProject is a documentation generator add-in 160 | DocProject/buildhelp/ 161 | DocProject/Help/*.HxT 162 | DocProject/Help/*.HxC 163 | DocProject/Help/*.hhc 164 | DocProject/Help/*.hhk 165 | DocProject/Help/*.hhp 166 | DocProject/Help/Html2 167 | DocProject/Help/html 168 | 169 | # Click-Once directory 170 | publish/ 171 | 172 | # Publish Web Output 173 | *.[Pp]ublish.xml 174 | *.azurePubxml 175 | # Note: Comment the next line if you want to checkin your web deploy settings, 176 | # but database connection strings (with potential passwords) will be unencrypted 177 | *.pubxml 178 | *.publishproj 179 | 180 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 181 | # checkin your Azure Web App publish settings, but sensitive information contained 182 | # in these scripts will be unencrypted 183 | PublishScripts/ 184 | 185 | # NuGet Packages 186 | *.nupkg 187 | # NuGet Symbol Packages 188 | *.snupkg 189 | # The packages folder can be ignored because of Package Restore 190 | **/[Pp]ackages/* 191 | # except build/, which is used as an MSBuild target. 192 | !**/[Pp]ackages/build/ 193 | # Uncomment if necessary however generally it will be regenerated when needed 194 | #!**/[Pp]ackages/repositories.config 195 | # NuGet v3's project.json files produces more ignorable files 196 | *.nuget.props 197 | *.nuget.targets 198 | 199 | # Microsoft Azure Build Output 200 | csx/ 201 | *.build.csdef 202 | 203 | # Microsoft Azure Emulator 204 | ecf/ 205 | rcf/ 206 | 207 | # Windows Store app package directories and files 208 | AppPackages/ 209 | BundleArtifacts/ 210 | Package.StoreAssociation.xml 211 | _pkginfo.txt 212 | *.appx 213 | *.appxbundle 214 | *.appxupload 215 | 216 | # Visual Studio cache files 217 | # files ending in .cache can be ignored 218 | *.[Cc]ache 219 | # but keep track of directories ending in .cache 220 | !?*.[Cc]ache/ 221 | 222 | # Others 223 | ClientBin/ 224 | ~$* 225 | *~ 226 | *.dbmdl 227 | *.dbproj.schemaview 228 | *.jfm 229 | *.pfx 230 | *.publishsettings 231 | orleans.codegen.cs 232 | 233 | # Including strong name files can present a security risk 234 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 235 | #*.snk 236 | 237 | # Since there are multiple workflows, uncomment next line to ignore bower_components 238 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 239 | #bower_components/ 240 | 241 | # RIA/Silverlight projects 242 | Generated_Code/ 243 | 244 | # Backup & report files from converting an old project file 245 | # to a newer Visual Studio version. Backup files are not needed, 246 | # because we have git ;-) 247 | _UpgradeReport_Files/ 248 | Backup*/ 249 | UpgradeLog*.XML 250 | UpgradeLog*.htm 251 | ServiceFabricBackup/ 252 | *.rptproj.bak 253 | 254 | # SQL Server files 255 | *.mdf 256 | *.ldf 257 | *.ndf 258 | 259 | # Business Intelligence projects 260 | *.rdl.data 261 | *.bim.layout 262 | *.bim_*.settings 263 | *.rptproj.rsuser 264 | *- [Bb]ackup.rdl 265 | *- [Bb]ackup ([0-9]).rdl 266 | *- [Bb]ackup ([0-9][0-9]).rdl 267 | 268 | # Microsoft Fakes 269 | FakesAssemblies/ 270 | 271 | # GhostDoc plugin setting file 272 | *.GhostDoc.xml 273 | 274 | # Node.js Tools for Visual Studio 275 | .ntvs_analysis.dat 276 | node_modules/ 277 | 278 | # Visual Studio 6 build log 279 | *.plg 280 | 281 | # Visual Studio 6 workspace options file 282 | *.opt 283 | 284 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 285 | *.vbw 286 | 287 | # Visual Studio LightSwitch build output 288 | **/*.HTMLClient/GeneratedArtifacts 289 | **/*.DesktopClient/GeneratedArtifacts 290 | **/*.DesktopClient/ModelManifest.xml 291 | **/*.Server/GeneratedArtifacts 292 | **/*.Server/ModelManifest.xml 293 | _Pvt_Extensions 294 | 295 | # Paket dependency manager 296 | .paket/paket.exe 297 | paket-files/ 298 | 299 | # FAKE - F# Make 300 | .fake/ 301 | 302 | # CodeRush personal settings 303 | .cr/personal 304 | 305 | # Python Tools for Visual Studio (PTVS) 306 | __pycache__/ 307 | *.pyc 308 | 309 | # Cake - Uncomment if you are using it 310 | # tools/** 311 | # !tools/packages.config 312 | 313 | # Tabs Studio 314 | *.tss 315 | 316 | # Telerik's JustMock configuration file 317 | *.jmconfig 318 | 319 | # BizTalk build output 320 | *.btp.cs 321 | *.btm.cs 322 | *.odx.cs 323 | *.xsd.cs 324 | 325 | # OpenCover UI analysis results 326 | OpenCover/ 327 | 328 | # Azure Stream Analytics local run output 329 | ASALocalRun/ 330 | 331 | # MSBuild Binary and Structured Log 332 | *.binlog 333 | 334 | # NVidia Nsight GPU debugger configuration file 335 | *.nvuser 336 | 337 | # MFractors (Xamarin productivity tool) working folder 338 | .mfractor/ 339 | 340 | # Local History for Visual Studio 341 | .localhistory/ 342 | 343 | # BeatPulse healthcheck temp database 344 | healthchecksdb 345 | 346 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 347 | MigrationBackup/ 348 | 349 | # Ionide (cross platform F# VS Code tools) working folder 350 | .ionide/ 351 | --------------------------------------------------------------------------------