Get the App
SLTechnology News&Howtos  ›  Development  › 

How to generate text CAPTCHA by Unity

Shulou Source: shulou.com Published: 2022-06-03 09:47:57 11月15日 Update

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!

Tags: Validation generation text tools articles content length not much code author most characters strings time more version user knowledge type website Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL vpn Xiaomi OPPO Reno Microsoft