彩色驗證碼圖片可以防禦別人的攻擊?
因為當別人用輪詢技術類比登入的時候,他並不知道你的驗證碼是什麼,也擷取不到,因為這是一張圖片,電腦並不能識別裡面的數字是什麼(除非破解驗證碼裡面的幹擾,再利用相關的圖片識別技術有可能讀出驗證碼,這裡先不扯這個)。讀不出驗證碼就沒有機會輪詢訪問了,當然我們後台判斷的時候一定要先判斷驗證碼是否正確,以防止佔用伺服器資源。
3、隨機數 code
①數字隨機數
1 /// <summary>
2 /// 數字隨機數
3 /// </summary>
4 /// <returns></returns>
5 private string getrndnum()
6 {
7 string code = string.empty;
8 random random = new random();
9 for (int i = 0; i < 4; i++)
10 {
11 code = code + random.next(9).tostring();
12 }
13 return code;
14 }
②字串隨機數
1 /// <summary>
2 /// 字串驗證碼
3 /// </summary>
4 /// <returns></returns>
5 private string getrndstr()
6 {
7 string vchar = "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";
8 string[] vcarray = vchar.split(',');
9 string checkcode = string.empty;
10 random rand = new random();
11 for (int i = 0; i < 4; i++)
12 {
13 rand = new random(unchecked((int)datetime.now.ticks));//為了得到不同的隨機序列
14 int t = rand.next(vcarray.length);// the exclusive upper bound of the random number to be generated. maxvalue must be greater than or equal to zero,下標從0開始
15 checkcode += vcarray[t];
16 }
17 return checkcode;
18 }