Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to generate text CAPTCHA by Unity

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

Editor to share with you how to generate Unity text verification code, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to understand it!

Text verification code

Since I often use Unity to develop webgl versions, I see a lot of CAPTCHA verification when users log in to the site. The tool class text verification code of Unity is written as follows:

Tool class: VerificationCode

Using System.Collections;using System.Collections.Generic;using System.Text / the tool class is: generate CAPTCHA / / author: hys/// time: 2019.12.30 shock / E-mail: 840917807@qq.com/// public class VerificationCode {private static char [] constant = {'0pm] constant = {' 0# * $$} 1, # 2, 3, 4, 5, 6, 7, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 4, 4, 4, 4, 6, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 'fendy, makeshift, pageantry, pageantry, punitive, wishy-washy, wishy-washy-wishy-wishy- 'Lindsay, recorder, etc. / get the randomly generated CAPTCHA / length / public static string SetDeleKey (int Length) {StringBuilder newRandom = new StringBuilder (62); System.Random rd = new System.Random (); for (int I = 0; I < Length; iCAPTCHA +) {newRandom.Append (certificate [rd.Next (62)]) / / rd.Next (62) returns a non-negative random number less than 62, and Append splices Length sub-random codes} return newRandom.ToString ();}}

Unity script

Using System.Collections;using System.Collections.Generic;using UnityEngine;using UnityEngine.UI;public class HuangVerificationCodeTextScripts: MonoBehaviour {private Text verificationCodeText; / / CAPTCHA Text. Private void Awake () {init ();} void Start () {} void Update () {} / initialize / private void init () {verificationCodeText = GameObject.Find ("VerificationCodeText") .GetComponent () } / generate CAPTCHA / CAPTCHA length / CAPTCHA of string type public string generateVerificationCode (int length) {string code= VerificationCode.SetDeleKey (length); verificationCodeText.text = code; return code;}} above is all the content of the article "how to generate text CAPTCHA by Unity". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report