C# 如何生成验证码

string str = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890";

Random ran = new Random();

int r = ran.Next(0, str.Length);

string a = str.Substring(r, 1);

用循环来选择验证码的位数:

string y = "";
Random ran = new Random();
for (int x = 1; x < 5; x++)
{
int r = ran.Next(0, str.Length);
string a = str.Substring(r, 1);
y = y + a;
}

posted on 2017-11-02 15:44  段了的弦  阅读(956)  评论(0编辑  收藏  举报