string[] test = { "A", "B", "C", "E", "F", "1", "2", "3", "4" };
int length = 4;
string str = string.Empty;
long tick = DateTime.Now.Ticks;
Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
for (int i = 0; i < length; i++)
{
str += test[ran.Next(test.Length)];
}
Console.WriteLine(str);
public string CreateCode(int codeLength)
{
string so = "2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,L,M,N,P,Q,R,S,T,U,V,W,X,Y,Z";
string[] strArr=so.Split(',');
string code = "";
Random rand=new Random();
for (int i = 0; i < codeLength; i++)
{
code+=strArr[rand.Next(0, strArr.Length)];
}
return code;
}
用这个就可以
string[] test = { "A", "B", "C", "E", "F", "1", "2", "3", "4" };
int length = 4;
string str = string.Empty;
long tick = DateTime.Now.Ticks;
Random ran = new Random((int)(tick & 0xffffffffL) | (int)(tick >> 32));
for (int i = 0; i < length; i++)
{
str += test[ran.Next(test.Length)];
}
Console.WriteLine(str);
感觉验证码还是不区分大小写比较好。。。
@水牛刀刀:
嗯,是的,最好把相似的去掉,如i,1,o,O之类的
上面的随手帖过来的,我修改下
@水牛刀刀: 现在流行做法是显示时区分大小写,输入时不区分。
@artwl: 很好,找的就是这样的,谢谢啦大侠!
在图片生成上大小写必须随机,没了大小写破解难度大大降低,去掉相似歧义的字符倒是应该的,比如0跟O。
在用户输入时不应该区分大小写。