生成验证码 [英] generate verification code

查看:94
本文介绍了生成验证码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何生成验证码并获取字符串中的值

how to generate verification code and take the value in string

推荐答案

请尝试以下..

Try below..
using System.Text;
using System.IO;


  static int RandomNumber(int min, int max)
    {
        Random random = new Random();
        return random.Next(min, max);
    }

private string RandomString(int size)// for random alphabets
    {
        StringBuilder builder = new StringBuilder();
        Random random = new Random();
        char ch;
        for (int i = 0; i < size; i++)
        {
            ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * random.NextDouble() + 65)));
            builder.Append(ch);
        }

        return builder.ToString();
    }
    static class RandomUtil // for random alphanumerics
    {
        /// <summary>
        /// Get random string of 11 characters.
        /// </summary>
        /// <returns>Random string.</returns>
        public static string GetRandomString()
        {
            string path = Path.GetRandomFileName();
            path = path.Replace(".", ""); // Remove period.
            return path;
        }
    }

     // random function where ever you wanted
     Label1.Text = RandomUtil.GetRandomString(); // for alphanumeric
     Label2.Text = RandomString(10); // for alphanumeric of length 10
     Label3.Text = RandomNumber(10,10000); // for random number between 10 and 10000



请参阅以下链接..

http://www.dotnetperls.com/random-string [ ^ ]


这篇关于生成验证码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆