asp.net c# 彩色驗證碼圖片產生程式(1/3)

來源:互聯網
上載者:User

彩色驗證碼圖片可以防禦別人的攻擊?
因為當別人用輪詢技術類比登入的時候,他並不知道你的驗證碼是什麼,也擷取不到,因為這是一張圖片,電腦並不能識別裡面的數字是什麼(除非破解驗證碼裡面的幹擾,再利用相關的圖片識別技術有可能讀出驗證碼,這裡先不扯這個)。讀不出驗證碼就沒有機會輪詢訪問了,當然我們後台判斷的時候一定要先判斷驗證碼是否正確,以防止佔用伺服器資源。


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         }

首頁 1 2 3 末頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.