欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當前位置:主頁 > 軟件編程 > C#教程 >

Unity工具類之生成文本驗證碼

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

本文實例為大家分享了Unity生成文本驗證碼的具體代碼,供大家參考,具體內(nèi)容如下

文本驗證碼

由于我經(jīng)常使用Unity進行webgl版本的開發(fā),看到網(wǎng)站上面用戶登錄有很多的驗證碼驗證。借鑒相關(guān)博客,寫了Unity的工具類文本驗證碼,代碼如下:

工具類:VerificationCode

using System.Collections;
using System.Collections.Generic;
using System.Text;
/// <summary>
/// 該工具類為:生成驗證碼
/// 作者:hys
/// 時間:2019.12.30
/// 郵箱:840917807@qq.com
/// </summary>

public class VerificationCode
{

  private static char[] constant =
  {
    '0','1','2','3','4','5','6','7','8','9',
    'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',
    'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
  };

  /// <summary>
  /// 獲取隨機生成的驗證碼
  /// </summary>
  /// <param name="Length">長度</param>
  /// <returns></returns>
  public static string SetDeleKey(int Length)
  {
      StringBuilder newRandom = new StringBuilder(62);
      System.Random rd = new System.Random();
      for (int i = 0; i < Length; i++)
      {
        newRandom.Append(constant[rd.Next(62)]); //rd.Next(62)返回小于62的非負隨機數(shù),Append將Length次隨機的碼進行拼接
      }
    return newRandom.ToString();
  }
  
}

Unity腳本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HuangVerificationCodeTextScripts : MonoBehaviour
{
  private Text verificationCodeText; //驗證碼Text.
  private void Awake()
  {
    init();
  }
  void Start()
  {
    
  }
  void Update()
  {
    
  }
  /// <summary>
  /// 進行初始化
  /// </summary>
  private void init()
  {
    verificationCodeText = GameObject.Find("VerificationCodeText").GetComponent<Text>();
  }



  /// <summary>
  /// 生成驗證碼
  /// </summary>
  /// <param name="length">驗證碼長度</param>
  /// <returns>字符串類型的驗證碼</returns>
  public string generateVerificationCode(int length)
  {
    string code= VerificationCode.SetDeleKey(length);
    verificationCodeText.text = code;
    return code;
  }

}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:C#中HttpWebRequest、WebClient、HttpClient的使用詳解

欄    目:C#教程

下一篇:C# 打印網(wǎng)頁不顯示頁眉頁腳的實現(xiàn)方法

本文標題:Unity工具類之生成文本驗證碼

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/4567.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有