#region 验证码长度(默认20个验证码的长度)
int length = 20;
public int Length
{
get { return length; }
set { length = value; }
}
#endregion
#region 生成随机字符码(二维码)
public string CreateVerifyCode(int codeLen)
{
if (codeLen == 0)
{
codeLen = this.Length;
}
string[] arr = { "0","1"};
string code = "";
int randValue = -1;
Random rand = new Random(unchecked((int)DateTime.Now.Ticks));
for (int i = 0; i < codeLen; i++)
{
randValue = rand.Next(arr.Length);
code += arr[randValue];
}
return code;
}
public string CreateVerifyCode()
{
return CreateVerifyCode(0);
}
#endregion
该博客介绍了一个用于生成二维码的随机字符码方法,包括设置验证码长度为20位,并提供了一个生成指定长度随机字符串的函数,使用了包含'0'和'1'的字符数组。
928

被折叠的 条评论
为什么被折叠?



