欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

ASP.NET如何制作驗證碼-創(chuàng)新互聯(lián)

這篇文章給大家分享的是有關(guān)ASP.NET如何制作驗證碼的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考,一起跟隨小編過來看看吧。

西安ssl適用于網(wǎng)站、小程序/APP、API接口等需要進行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:13518219792(備注:SSL證書合作)期待與您的合作!
 /// <summary>
 /// 驗證碼生成類
 /// </summary>
 public class verify_code : IHttpHandler, IRequiresSessionState
 {
  public void ProcessRequest(HttpContext context)
  {
   int codeW = 80;
   int codeH = 22;
   int fontSize = 16;
   string chkCode = string.Empty;
   //顏色列表,用于驗證碼、噪線、噪點 
   Color[] color = { Color.Black, Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Brown, Color.Brown, Color.DarkBlue };
   //字體列表,用于驗證碼 
   string[] font = { "Times New Roman", "Verdana", "Arial", "Gungsuh", "Impact" };
   //驗證碼的字符集,去掉了一些容易混淆的字符 
   char[] character = { '0', '1', '2', '3', '4', '5', '6', '8', '9' };
   Random rnd = new Random();
   //生成驗證碼字符串 
   for (int i = 0; i < 4; i++)
   {
    chkCode += character[rnd.Next(character.Length)];
   }
   //寫入Session
   context.Session["sys_verify_code"] = chkCode;
   //創(chuàng)建畫布
   Bitmap bmp = new Bitmap(codeW, codeH);
   Graphics g = Graphics.FromImage(bmp);
   g.Clear(Color.White);
   //畫噪線 
   for (int i = 0; i < 4; i++)
   {
    int x1 = rnd.Next(codeW);
    int y1 = rnd.Next(codeH);
    int x2 = rnd.Next(codeW);
    int y2 = rnd.Next(codeH);
    Color clr = color[rnd.Next(color.Length)];
    g.DrawLine(new Pen(clr), x1, y1, x2, y2);
   }
   //畫驗證碼字符串 
   for (int i = 0; i < chkCode.Length; i++)
   {
    string fnt = font[rnd.Next(font.Length)];
    Font ft = new Font(fnt, fontSize);
    Color clr = color[rnd.Next(color.Length)];
    g.DrawString(chkCode[i].ToString(), ft, new SolidBrush(clr), (float)i * 18 + 2, (float)0);
   }
   //畫噪點 
   for (int i = 0; i < 100; i++)
   {
    int x = rnd.Next(bmp.Width);
    int y = rnd.Next(bmp.Height);
    Color clr = color[rnd.Next(color.Length)];
    bmp.SetPixel(x, y, clr);
   }
   //清除該頁輸出緩存,設(shè)置該頁無緩存 
   context.Response.Buffer = true;
   context.Response.ExpiresAbsolute = System.DateTime.Now.AddMilliseconds(0);
   context.Response.Expires = 0;
   context.Response.CacheControl = "no-cache";
   context.Response.AppendHeader("Pragma", "No-Cache");
   //將驗證碼圖片寫入內(nèi)存流,并將其以 "image/Png" 格式輸出 
   MemoryStream ms = new MemoryStream();
   try
   {
    bmp.Save(ms, ImageFormat.Png);
    context.Response.ClearContent();
    context.Response.ContentType = "image/Png";
    context.Response.BinaryWrite(ms.ToArray());
   }
   finally
   {
    //顯式釋放資源 
    bmp.Dispose();
    g.Dispose();
   }
  }

  public bool IsReusable
  {
   get
   {
    return false;
   }
  }
 }

基本驗證生成代碼demo:

using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Web;

public partial class image : System.Web.UI.Page
{
 protected void Page_Load(object sender, EventArgs e)
 {
  string tmp = RndNum(4);
  HttpCookie a = new HttpCookie("ImageV", tmp);
  Response.Cookies.Add(a);
  this.ValidateCode(tmp);
 }

 private void ValidateCode(string VNum)
 {
  Bitmap Img = null;
  Graphics g = null;
  MemoryStream ms = null;
  int gheight = VNum.Length * 12;
  Img = new Bitmap(gheight, 25);
  g = Graphics.FromImage(Img);
  //背景顏色
  g.Clear(Color.White);
  //文字字體
  Font f = new Font("Arial Black", 10);
  //文字顏色
  SolidBrush s = new SolidBrush(Color.Black);
  g.DrawString(VNum, f, s, 3, 3);
  ms = new MemoryStream();
  Img.Save(ms, ImageFormat.Jpeg);
  Response.ClearContent();
  Response.ContentType = "image/Jpeg";
  Response.BinaryWrite(ms.ToArray());

  g.Dispose();
  Img.Dispose();
  Response.End();
 }

 private string RndNum(int VcodeNum)
 {
  string Vchar = "0,1,2,3,4,5,6,7,8,9,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";
  string[] VcArray = Vchar.Split(new Char[] { ',' });
  string VNum = "";
  int temp = -1;

  Random rand = new Random();

  for (int i = 1; i < VcodeNum + 1; i++)
  {
   if (temp != -1)
   {
    rand = new Random(i * temp * unchecked((int)DateTime.Now.Ticks));
   }

   int t = rand.Next(35);
   if (temp != -1 && temp == t)
   {
    return RndNum(VcodeNum);
   }
   temp = t;
   VNum += VcArray[t];
  }
  return VNum;
 }

}

感謝各位的閱讀!關(guān)于“ASP.NET如何制作驗證碼”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

網(wǎng)頁標(biāo)題:ASP.NET如何制作驗證碼-創(chuàng)新互聯(lián)
鏈接地址:http://www.aaarwkj.com/article32/csoopc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、網(wǎng)站策劃、品牌網(wǎng)站建設(shè)、電子商務(wù)、網(wǎng)站排名搜索引擎優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

綿陽服務(wù)器托管
国产高清自拍视频在线一区| 香蕉久草官网视频观看| 国产午夜视频成人无遮挡| 永久永久免费黄色一级片| 内射极品美女在线观看| av成人黄色片在线播放| 中文字幕日韩一区二区| 亚洲精品中文字幕乱码三区91| 又黄又爽又刺激的性视频| 特黄特色的日本大片| 色自拍偷拍另类欧洲美女| 日韩欧美国产成人在线观看| 少妇高潮视频在线观看| 日韩欧美二区三区精品在线| 欧美三级特黄在线播放| 18岁以下禁看视频网站| 亚洲精品紧身裙女教师av| 精品国产一区二区三区不卡| 成人高清乱码一区二区三区| 欧美日韩美足一区二区| 日韩欧美国产精品一区二区| 一区二区三区欧美日韩| 日韩在线视频精品一区| 2021最新四虎永久免费| 国产精品久久护士96| 最新91熟女九色地址| 日韩欧美国产麻豆91在线精品| 国产自愉自愉免费精品七| 国产精品一区二区三区专区| 青青草手机在线视频免费观看| 国产大片在线观看一区二区| 久久久久精品国产亚洲av影院| 日韩精品一区二区三区av在线| 国产内射一级一片内射高清视频1| 久久女婷五月综合色啪色老板| 亚洲精品一区二区播放| 欧美一区日韩二区国产三区| 日韩中文字幕在线乱码| 亚洲最大av在线精品国产| 亚欧成人永久免费视频| 黄色亚洲日本欧美在线观看|