In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how LazyCaptcha customizes random CAPTCHAs and fonts. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Introduction
LazyCaptcha is a graphic CAPTCHA module based on .net Standard 2.1imitating EasyCaptcha and SimpleCaptcha.
At present, Gitee 52star, if it is helpful to you, please don't be stingy with some stars.
one。 Custom random CAPTCHA (version 1.1.2 required)
Random here refers to CaptchaType random, movement random and so on. You can set any CaptchaOptions option value. Each time the verification code is refreshed, the effect is as follows:
I don't know if this need really exists.
1. Custom RandomCaptcha/// random verification code / public class RandomCaptcha: DefaultCaptcha {private static readonly Random random = new (); private static readonly CaptchaType [] captchaTypes = Enum.GetValues () Public RandomCaptcha (IOptionsSnapshot options, IStorage storage): base (options, storage) {} / update options / protected override void ChangeOptions (CaptchaOptions options) / / Random CAPTCHA type options.CaptchaType = captchaTypes [random.Next (0, captchaTypes.Length)] / / when doing arithmetic, CodeLength refers to the number of numbers if (options.CaptchaType.IsArithmetic ()) {options.CodeLength = 2;} else options.CodeLength = 4 / / if Chinese is included, use kaiti font, otherwise garbled if (options.CaptchaType.ContainsChinese ()) options.ImageOption.FontFamily = DefaultFontFamilys.Instance.Kaiti; options.ImageOption.FontSize = 24; options.ImageOption.FontFamily = DefaultFontFamilys.Instance.Actionj; / / Random options.ImageOption.Animation = random.Next (2) = = 0 / / interference line random options.ImageOption.InterferenceLineCount = random.Next (1,4); / / Bubble random options.ImageOption.BubbleCount = random.Next (1,4); / / other options.} 2. Inject RandomCaptcha// memory storage, configure builder.Services.AddCaptcha (builder.Configuration) based on appsettings.json; / / enable random verification code builder.Services.Add (ServiceDescriptor.Scoped ()); II. Custom font
Use KG HAPPY font, as shown in the figure:
1. Looking for fonts
You can find your favorite fonts through fontspace.
two。 Put the font into the project and set it to embed the resource.
Of course, you can not as an embedded resource, it is also possible to put it in a specific directory, as long as you make some changes to the following ResourceFontFamilysFinder.
3. Define the help class for finding fonts. The example uses ResourceFontFamilysFinderpublic class ResourceFontFamilysFinder {private static Lazy _ fontFamilies = new Lazy (() = > {var fontFamilies = new List (); var assembly = Assembly.GetExecutingAssembly (); var names = assembly.GetManifestResourceNames (); if (names?.Length > 0 = = true) {var fontCollection = new FontCollection ()) Foreach (var name in names) {if (! name.EndsWith ("ttf")) continue; fontFamilies.Add (fontCollection.Add (assembly.GetManifestResourceStream (name));}} return fontFamilies;}); public static FontFamily Find (string name) return _ fontFamilies.Value.First (e = > e.Name = = name);}} 4. Set option// memory storage and configure builder.Services.AddCaptcha based on appsettings.json (builder.Configuration, options = > {/ / Custom font options.ImageOption.FontSize = 28; options.ImageOption.FontFamily = ResourceFontFamilysFinder.Find ("KG HAPPY"); / / the name of the font is displayed when you open the ttf file}) On "LazyCaptcha how to customize random CAPTCHA and font" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.