惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Cisco Blogs
T
The Exploit Database - CXSecurity.com
G
GRAHAM CLULEY
AI
AI
腾讯CDC
月光博客
月光博客
P
Privacy International News Feed
aimingoo的专栏
aimingoo的专栏
博客园 - 聂微东
Latest news
Latest news
宝玉的分享
宝玉的分享
The Last Watchdog
The Last Watchdog
H
Hacker News: Front Page
博客园 - 【当耐特】
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog
D
Docker
D
DataBreaches.Net
O
OpenAI News
IT之家
IT之家
T
Threat Research - Cisco Blogs
S
Securelist
S
Secure Thoughts
V
Visual Studio Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
A
Arctic Wolf
I
Intezer
Simon Willison's Weblog
Simon Willison's Weblog
L
Lohrmann on Cybersecurity
C
Cyber Attacks, Cyber Crime and Cyber Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tor Project blog
Google DeepMind News
Google DeepMind News
J
Java Code Geeks
Help Net Security
Help Net Security
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
N
Netflix TechBlog - Medium
F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
博客园 - Franky
C
Check Point Blog
美团技术团队
Hugging Face - Blog
Hugging Face - Blog
罗磊的独立博客
Forbes - Security
Forbes - Security
F
Full Disclosure
S
Security @ Cisco Blogs
B
Blog RSS Feed

博客园 - Nikos

又是一年,写个总结吧... 5.23 随笔 - Nikos - 博客园 Feb.19 Come back Jan.17 wtiring 地址 笔记 认识 C#中使用ref和out (转) 穿过代理服务器取远程用户真实IP地址 深入理解.NET内存回收机制 (转) 贴板--c#.net中类的覆写(OverRide) 语言的发展就是库的发展 保证你现在和未来不失业的十种关键技术(转) 再议Exception(转) December 4, 2005 说明 建立您自己的、支持选项卡的 Web 浏览器(转) 针对 Java 开发人员的 C# 编程语言(转) 从 C++ 向 C# 迁移(转) Visual Studio Team System单服务器部署指南(转)
ASP.net 验证码(C#) (转)-----很实用的一个东西
Nikos · 2005-12-11 · via 博客园 - Nikos

public class ValidateCode : System.Web.UI.Page { private void Page_Load(object sender, System.EventArgs e) { this.CreateCheckCodeImage(GenerateCheckCode()); } #region web 窗体设计器生成的代码 override protected void OnInit(EventArgs e) { // // CODEGEN: 该调用是 asp.NET web 窗体设计器所必需的。 // InitializeComponent(); base.OnInit(e); } ///

/// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 ///

private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); } #endregion private string GenerateCheckCode() { int number; char code; string checkCode = String.Empty; System.Random random = new Random(); for(int i=0; i<5; i++) { number = random.Next(); if(number % 2 == 0) code = (char)('0' + (char)(number % 10)); else code = (char)('A' + (char)(number % 26)); checkCode += code.ToString(); } Response.Cookies.Add(new HttpCookie("CheckCode", checkCode)); return checkCode; } private void CreateCheckCodeImage(string checkCode) { if(checkCode == null || checkCode.Trim() == String.Empty) return; System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((checkCode.Length * 12.5)), 22); Graphics g = Graphics.FromImage(image); try { //生成随机生成器 Random random = new Random(); //清空图片背景色 g.Clear(Color.White); //画图片的背景噪音线 for(int i=0; i<25; 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); } Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic)); System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue, Color.DarkRed, 1.2f, true); g.DrawString(checkCode, font, brush, 2, 2); //画图片的前景噪音点 for(int i=0; i<100; 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.ContentType = "image/Gif"; Response.BinaryWrite(ms.ToArray()); } finally { g.Dispose(); image.Dispose(); } } }