好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識庫 > 深入學習.net驗證碼生成及使用方法

深入學習.net驗證碼生成及使用方法

熱門標簽:海東防封電銷卡 云南外呼系統代理 南昌自動外呼系統線路 西寧電銷外呼系統公司 寧德防封版電銷卡 聊城智能電銷機器人電話 安陸市地圖標注app 辦公用地圖標注網點怎么操作 上海市三維地圖標注

小課堂:驗證碼的作用:

      幾年前,大部分網站、論壇之類的是沒有驗證碼的,因為對于一般用戶來說驗證碼只是增加了用戶的操作,降低了用戶的體驗。但是后來各種灌水機器人、投票機器人、惡意注冊機器人層出不窮,大大增加了網站的負擔同時也給網站數據庫帶來了大量的垃圾數據。為了防止各種機器人程序的破壞,于是程序員想出了只有人眼能夠識別的,程序不容易識別的驗證碼!

      驗證碼是一個圖片,將字母、數字甚至漢字作為圖片的內容,這樣一張圖片中的內容用人眼很容易識別,而程序將無法識別。在進行數據庫操作之前(比如登錄驗證、投票、發帖、回復、注冊等等)程序首先驗證客戶端提交的驗證碼是否與圖片中的內容相同,如果相同則進行數據庫操作,不同則提示驗證碼錯誤,不進行數據庫操作。這樣各種機器人程序就被拒之門外了!

      但是隨著計算機科學的發展,模式識別等技術越來越成熟,于是編寫機器人程序的家伙可以通過程序將直接寫在圖片中的內容識別出來,然后提交到服務器,這樣驗證碼將形同虛設。為了防止機器人程序的識別,驗證碼的圖片生成也不斷在發展,加入干擾點、干擾線,文字變形、變換角度位置,顏色不同……各種防止計算機識別的技術也應用到驗證碼中。就在這兩種技術的競爭中,于是便形成了我們現在看到的驗證碼,已經有很多人在抱怨“這是什么驗證碼哦,人眼都分辨不清楚是什么”,一切也是無奈。

了解了驗證碼的作用,下面寫一個簡單的驗證碼生成及使用的實例

先建個頁面用來展示驗證碼和判斷驗證碼輸入是否正確

html xmlns="http://www.w3.org/1999/xhtml">
head runat="server">
 title>/title>
 script src="Scripts/jquery-1.4.1.min.js" type="text/javascript">/script>
 script type="text/javascript">
 //點擊切換驗證碼
 function f_refreshtype() {
 var Image1 = document.getElementById("img");
 if (Image1 != null) {
 Image1.src = Image1.src + "?";
 }
 } 
 /script>
/head>
body>
 form id="form1" runat="server">
 div>
 table>
 tr>
 td>
  asp:TextBox ID="TextBox1" runat="server">/asp:TextBox>
 /td>
 td>
  img src="png.aspx" id="img" onclick="f_refreshtype()" />
 /td>
 td>
  asp:Button ID="Button1" runat="server" Text="確定" />
 /td>
 /tr>
 /table>
 /div>
 /form>
/body>
/html>

此頁面后臺對驗證碼進行驗證

 protected void Page_Load(object sender, EventArgs e)
 {
 //生成的驗證碼被保存到session中
 if (Session["CheckCode"] != null)
 {
 string checkcode = Session["CheckCode"].ToString();
 if (this.TextBox1.Text == checkcode)
 {
  ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('驗證碼輸入正確!')", true);
 }
 else
 {
  ClientScript.RegisterClientScriptBlock(this.GetType(), "", "alert('驗證碼輸入錯誤!')", true);
 }
 }

 }

生成驗證碼頁面png.aspx

 protected void Page_Load(object sender, EventArgs e)
 {
 if (!IsPostBack)
 {
 CreateCheckCodeImage(GenerateCheckCodes(4));
 }
 }
 public void ShowAuthCode(Stream stream, out string code)
 {
 Random random = new Random();
 code = random.Next(1000, 9999).ToString();

 Bitmap bitmap = CreateAuthCode(code);
 bitmap.Save(stream, System.Drawing.Imaging.ImageFormat.Gif);
 }

 private string GenerateCheckCodes(int iCount)
 {
 int number;
 string checkCode = String.Empty;
 int iSeed = DateTime.Now.Millisecond;
 System.Random random = new Random(iSeed);
 for (int i = 0; i  iCount; i++)
 {
 number = random.Next(10);
 checkCode += number.ToString();
 }
 Session["CheckCode"] = checkCode;
 return checkCode;
 }

 private Bitmap CreateAuthCode(string str)
 {
 Font fn = new Font("宋體", 12);
 Brush forecolor = Brushes.Black;
 Brush bgcolor = Brushes.White;
 PointF pf = new PointF(5, 5);
 Bitmap bitmap = new Bitmap(100, 25);
 Rectangle rec = new Rectangle(0, 0, 100, 25);
 Graphics gh = Graphics.FromImage(bitmap);
 gh.FillRectangle(bgcolor, rec);
 gh.DrawString(str, fn, forecolor, pf);
 return bitmap;
 }

 private void CreateCheckCodeImage(string checkCode)
 {
 if (checkCode == null || checkCode.Trim() == String.Empty)
 return;
 int iWordWidth = 15;
 int iImageWidth = checkCode.Length * iWordWidth;
 Bitmap image = new Bitmap(iImageWidth, 20);
 Graphics g = Graphics.FromImage(image);
 try
 {
 //生成隨機生成器 
 Random random = new Random();
 //清空圖片背景色 
 g.Clear(Color.White);

 //畫圖片的背景噪音點
 for (int i = 0; i  20; i++)
 {
  int x1 = random.Next(image.Width);
  int x2 = random.Next(image.Width);
  int y1 = random.Next(image.Height);
  int y2 = random.Next(image.Height);
  g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
 }

 //畫圖片的背景噪音線 
 for (int i = 0; i  2; i++)
 {
  int x1 = 0;
  int x2 = image.Width;
  int y1 = random.Next(image.Height);
  int y2 = random.Next(image.Height);
  if (i == 0)
  {
  g.DrawLine(new Pen(Color.Gray, 2), x1, y1, x2, y2);
  }

 }


 for (int i = 0; i  checkCode.Length; i++)
 {

  string Code = checkCode[i].ToString();
  int xLeft = iWordWidth * (i);
  random = new Random(xLeft);
  int iSeed = DateTime.Now.Millisecond;
  int iValue = random.Next(iSeed) % 4;
  if (iValue == 0)
  {
  Font font = new Font("Arial", 13, (FontStyle.Bold | System.Drawing.FontStyle.Italic));
  Rectangle rc = new Rectangle(xLeft, 0, iWordWidth, image.Height);
  LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Blue, Color.Red, 1.5f, true);
  g.DrawString(Code, font, brush, xLeft, 2);
  }
  else if (iValue == 1)
  {
  Font font = new System.Drawing.Font("楷體", 13, (FontStyle.Bold));
  Rectangle rc = new Rectangle(xLeft, 0, iWordWidth, image.Height);
  LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Blue, Color.DarkRed, 1.3f, true);
  g.DrawString(Code, font, brush, xLeft, 2);
  }
  else if (iValue == 2)
  {
  Font font = new System.Drawing.Font("宋體", 13, (System.Drawing.FontStyle.Bold));
  Rectangle rc = new Rectangle(xLeft, 0, iWordWidth, image.Height);
  LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Green, Color.Blue, 1.2f, true);
  g.DrawString(Code, font, brush, xLeft, 2);
  }
  else if (iValue == 3)
  {
  Font font = new System.Drawing.Font("黑體", 13, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Bold));
  Rectangle rc = new Rectangle(xLeft, 0, iWordWidth, image.Height);
  LinearGradientBrush brush = new LinearGradientBrush(rc, Color.Blue, Color.Green, 1.8f, true);
  g.DrawString(Code, font, brush, xLeft, 2);
  }
 }
 //////畫圖片的前景噪音點 
 //for (int i = 0; i  8; i++)
 //{
 // int x = random.Next(image.Width);
 // int y = random.Next(image.Height);
 // image.SetPixel(x, y, Color.FromArgb(random.Next()));
 //}
 //畫圖片的邊框線 
 g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
 System.IO.MemoryStream ms = new System.IO.MemoryStream();
 image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
 Response.ClearContent();
 Response.BinaryWrite(ms.ToArray());
 }
 finally
 {
 g.Dispose();
 image.Dispose();
 }
 }

您可能感興趣的文章:
  • asp.net登錄驗證碼實現方法
  • 詳解ASP.NET驗證碼的生成方法
  • asp.net生成字母和數字混合圖形驗證碼
  • asp.net簡單生成驗證碼的方法
  • ASP.NET驗證碼實現(附源碼)
  • .net生成驗證碼
  • asp.net驗證碼的簡單制作
  • 12306動態驗證碼啟發之ASP.NET實現動態GIF驗證碼(附源碼)
  • ASP.NET驗證碼(3種)
  • MVC使用極驗驗證制作登錄驗證碼學習筆記7

標簽:贛州 衢州 汕尾 崇左 平涼 洛陽 南寧 青海

巨人網絡通訊聲明:本文標題《深入學習.net驗證碼生成及使用方法》,本文關鍵詞  深入,學習,.net,驗證,碼,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《深入學習.net驗證碼生成及使用方法》相關的同類信息!
  • 本頁收集關于深入學習.net驗證碼生成及使用方法的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 免费看美女隐私视频网站| 久久久亚洲日韩| 999福利视频| 中国性猛交xxxxx免费看| 九九九国产精品成人免费视频 | 国产精品人妻无码久久久豆丁网 | 撕开她的内裤慢慢摸的网站| 日本熟妇无码亚洲成a人片动漫| 《甜性涩爱》未删减版在线| 好硬好湿好爽再深一点m视频| 久久99国产精品| 久久精品国产一区二区三区日韩 | 狠狠人妻久久久久久综合jiu| 好爽?要高潮了?深点快漫画| 国产欧美在线视频免费| 初尝了新婚小妇柔佳| 欧插网| 聚焦旅交會相約遊大理的内容| 欧美日韩成人??AV欧美| 99热国产这里只有精品免费| 佛山市| 99视频在线观看视频| 高潮肉欲老妇A片免费看| ?国产精品嫩草77AV麻酥酥| 国产特黄A三级三级三级丰满岳| 亚洲第9页| 十七岁韩国高清完整在线观看| 91的麻豆精品国产自产的推荐理由 | 懂色午夜精品久久久久久无码小说| 精品国产一区二区三区四区97| 999久久精品国产| 中文字幕久久网| 少妇扒开双腿自慰出白浆| 国产精品无码无片在线观看3D | 99视频精品全部国产盗摄视频| 曰本变态bdsm色虐tv| 毛茸茸妇女体内汇编| 中国女人性做爰免费看| 97国产精品一二三产区区别小说 | 亚洲精品无码国模av久久| 萌白酱甜味弥漫萌白酱在线|