In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how to implement CAPTCHA generation classes in HTML. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Verification code generation flow chart
First of all, let's take a look at the generation flow chart of the CAPTCHA generation class shared this time:
You can see that the coding generation pool described in this figure corresponds to several different coding contents. Here, it is mainly allowed to obtain different coding contents at the same time according to the parameter settings, thus reaching the combination of text, pinyin and Chinese characters to form a verification code. The specific rule settings are determined by the parameters.
The parsing of the pool code generated by »CAPTCHA
First of all, from the above flowchart analysis, we can see that this CAPTCHA generation pool needs to obtain different types of CAPTCHA data in parallel in order to meet the combined CAPTCHA, so there is the following code:
/ create CAPTCHA / 1: lowercase Pinyin 2: uppercase Pinyin 3: number 4: Chinese character / public static string CreateCode (string codeType = "1 | 2 | 3 | 4") {var code = string.Empty; try {if (string.IsNullOrWhiteSpace (codeType) | | codeType.IndexOf ('|')
< 0) { codeType = "1|2|3|4"; } var codeTypeArr = codeType.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); var strLen = codeTypeArr.Length; //任务 Task[] taskArr = new Task[strLen]; for (int i = 0; i < strLen; i++) { var val = codeTypeArr[i]; switch (val) { case "1": //小写拼音 taskArr[i] = Task.Factory.StartNew(() =>{return GetPinYinOrUpper (false);}); break; case "2": / / Capital Pinyin taskArr [I] = Task.Factory.StartNew (() = > {return GetPinYinOrUpper ();}); break; case "3": / / numeric taskArr [I] = Task.Factory.StartNew (() = > {return GetShuZi ();}); break; case "4": / / Chinese character taskArr [I] = Task.Factory.StartNew (() = > {return GetHanZi ();}) Break; default: break;}} / / waiting for 30s Task.WaitAll (taskArr, TimeSpan.FromSeconds (30)); foreach (var item in taskArr) {code + = item.Result;}} catch (Exception ex) {code = "I love my motherland";} return code;}
Here, we continue to use the keyword Task to distribute tasks to obtain different CAPTCHA contents. I think the most important thing is to determine the combination of CAPTCHA by setting string codeType = "1 | 2 | 3 | 4", which also achieves the diversity of CAPTCHA formats.
Draw the verification code on the picture
First of all, we need to make it clear that we want to draw the text on a certain picture, then we need to use the Graphics keyword to create a canvas to draw our verification code on the picture. Here is the code:
/ / generate CAPTCHA image stream / CAPTCHA text / stream public static byte [] CreateValidateCodeStream (string code = "I love my motherland", int fontSize = 18, int width = 0, int height = 0, string fontFamily = "Chinese italics") {var bb = new byte [0]; / / initialize canvas var padding = 2; var len = code.Length; width = width
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.