日期:2014-05-18  浏览次数:20436 次

谁能给个比较好看的验证码程序啊
网上找了一些
看有没有更好的

------解决方案--------------------
我刚好自己写了个程序!给分!
code.aspx页面代码!
<%@ Page language= "c# " Codebehind= "code.aspx.cs " AutoEventWireup= "false " Inherits= "ValidCode.CreateImage " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN " >
<HTML>
<HEAD>
<title> code </title>
<meta name= "GENERATOR " Content= "Microsoft Visual Studio .NET 7.1 ">
<meta name= "CODE_LANGUAGE " Content= "C# ">
<meta name= "vs_defaultClientScript " content= "JavaScript ">
<meta name= "vs_targetSchema " content= "http://schemas.microsoft.com/intellisense/ie5 ">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id= "Form1 " method= "post " runat= "server ">
<FONT face= "宋体 "> </FONT>
</form>
</body>
</HTML>

------------------------------------------------
code.aspx.cs 的代码:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;

namespace ValidCode
{
/// <summary>
/// 随机产生验证码,并将验证码绘制到图片上。
/// </summary>
public class CreateImage : System.Web.UI.Page
{

/// <summary>
/// 生成验证码。
/// </summary>
/// <returns> </returns>
private string GenerateCheckCode()
{
int number;
char code;
string checkCode = String.Empty;

// 声明并实例化随机数对象。
Random random = new Random( unchecked((int)DateTime.Now.Ticks));
for(int i=0; i <5; i++)
{
number = random.Next(1000);
if(number < 500)
//48在ASC码表中表示0!
//65在ASC码表中表示字母表中的A!~不是a!
code = (char)(48 + (number % 10));
else
code = (char)(65 + (number % 26));

checkCode += code.ToString();
}

// 将验证码保存到Session中。
Session[ "CheckCode "] = checkCode;

return checkCode;
}

/// <summary>
/// 利用生成的验证码绘图。
/// </summary>
/// <param name= "checkCode "> 验证码 </param>
private void CreateCheckCodeImage(string checkCode)
{
if(checkCode == null || checkCode.Trim() == String.Empty)
return;

// 声明并实例化一个画板对象。
Bitmap image = new 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 <50; 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.AliceBlue), x1, y1, x2, y2);
}

Font font = new System.Drawing.Font( "Arial ", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
System.Drawing.Drawing2D.LinearGradientBrush brus