上网浏览文章的时候,经常碰到非要你注册,才能够欣赏文章!
而且上面都半都有验证码的。起初,以为就是把几幅图连在一块,在搞个图片随机调换,后来才知道,其实没这么简单。
有没有哪位达人,高手告诉我,上怎么弄的啊
我的MSN:[email protected]
先谢谢各位了!!
而且上面都半都有验证码的。起初,以为就是把几幅图连在一块,在搞个图片随机调换,后来才知道,其实没这么简单。
有没有哪位达人,高手告诉我,上怎么弄的啊
我的MSN:[email protected]
先谢谢各位了!!
解决方案 »
- 请问大家 控件DataList <ItemTemplate >添加 Column 老是报错,什么原因?
- radio
- 视频播放器事件能捕获吗?
- 请问我想做一个站外搜索,怎么实现?比如嵌如百度的搜索引擎,该具体如何做?大家给点思路?
- 窗口传值问题,高分在线等!
- 水晶报表打印问题--总是多走一张纸!---马上要交项目了,请大家帮帮忙吧!(解决了你要多少分就给多少分
- 求救:用freetextbox的问题。在线等
- 检测到运行的不是ASP.NET 1.1 版.???
- 如何实现TREEVIEW的滚动条自动滚动到所选节点处!100分够不够
- asp.net有好的界面编辑器吗?
- 实现分页("上一页","下一页"),但是出错了!
- 100分!asp.net开发的人事系统案例或者其中某些功能部分也行!比如:请假.
然后用GDI画出来,再搞点水印(比如几道横线),丢到界面上
然后在别人注册的时候,用随即出来的字符串和他写的验证码比较就可以了(在代码里面)
{
SetValidateCode();
Response.Cache.SetNoStore();
}
private void SetValidateCode()
{
Bitmap newBitmap = new Bitmap(71, 23, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(newBitmap);
Random r = new Random();
g.Clear(Color.White);
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, 71, 23), Color.Red, Color.Blue, 1.2f, true); for (int i = 0; i < 50; i++)
{
int x1 = r.Next(newBitmap.Width);
int x2 = r.Next(newBitmap.Width);
int y1 = r.Next(newBitmap.Height);
int y2 = r.Next(newBitmap.Height);
g.DrawLine(new Pen(Color.FromArgb(r.Next())), x1, y1, x2, y2);
}
for (int i = 0; i < 100; i++)
{
int x = r.Next(newBitmap.Width);
int y = r.Next(newBitmap.Height);
newBitmap.SetPixel(x, y, Color.FromArgb(r.Next()));
}
string value = GenerateRandom(5);
Session["Code"] = value;
Font font = new Font("黑体", 14, System.Drawing.FontStyle.Bold);
Random rr = new Random();
int yy = rr.Next(1, 4);
g.DrawString(value, font, brush, 2, yy);
g.DrawRectangle(new Pen(Color.Silver), 0, 0, 70, 22);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
newBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/gif";
Response.BinaryWrite(ms.ToArray());
}
private static char[] constant =
{
'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'
};
public static string GenerateRandom(int Length)
{
System.Text.StringBuilder newRandom = new System.Text.StringBuilder(36);
Random rd = new Random();
for (int i = 0; i < Length; i++)
{
newRandom.Append(constant[rd.Next(36)]);
}
return newRandom.ToString();
}
}
然后在你需要的页面使用<img alt="验证码,看不清楚?请点击刷新验证码"
onclick="this.src='Validate.aspx'" src="Validate.aspx" style="cursor: pointer;
height: 26px" />
http://singlepine.cnblogs.com/articles/264894.html
里面有
NickLee.Web.UI.VB.CaptchaControl-------------验证码控件(W3C)