ylbtech-util: ashx-auth-黑色简洁验证码

ashx-auth-黑色简洁验证码

1.A,效果图返回顶部
 
1.B,源代码返回顶部

/ImageUniqueCode.ashx

<%@ WebHandler Language="C#" Class="ImageUniqueCode" %>

using System;
using System.Web;
using System.Drawing;
using System.Text; public class ImageUniqueCode : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{ public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "image/gif";
//建立Bitmap对象,绘图
Bitmap basemap = new Bitmap(, );
Graphics graph = Graphics.FromImage(basemap);
graph.FillRectangle(new SolidBrush(Color.White), , , , );
Font font = new Font(FontFamily.GenericSerif, , FontStyle.Bold, GraphicsUnit.Pixel);
Random r = new Random();
string letters = "ABCDEFGHIJKLMNPQRSTUVWXYZ0123456789";
string letter;
StringBuilder s = new StringBuilder(); //添加随机字符
for (int x = ; x < ; x++)
{
letter = letters.Substring(r.Next(, letters.Length - ), );
s.Append(letter);
graph.DrawString(letter, font, new SolidBrush(Color.Black), x * , r.Next(, ));
} //混淆背景
Pen linePen = new Pen(new SolidBrush(Color.Black), );
for (int x = ; x < ; x++)
graph.DrawLine(linePen, new Point(r.Next(, ), r.Next(, )), new Point(r.Next(, ), r.Next(, ))); //将图片保存到输出流中
basemap.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
context.Session["ImageUniqueCode"] = s.ToString();
context.Response.End();
} public bool IsReusable {
get {
return true;
}
} }
Attach
/FastFeedBack.ashx  【处理页面】
<%@ WebHandler Language="C#" Class="FastFeedback" %>

using System;
using System.Web; public class FastFeedback : IHttpHandler, System.Web.SessionState.IRequiresSessionState
{
//最终状态
public enum FeedbackState
{
UniqueCodeError = ,
Succeed = ,
Error = ,
Null =
} public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "text/plain";
context.Response.CacheControl = "no-cache"; //清空缓存 string code = context.Request["SecurityCode"];
string message = context.Request["Message"]; if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(message))
{
context.Response.Write(FeedbackState.Null.ToString());
context.Response.End();
return;
} try
{
if (code.ToUpper() == context.Session["ImageUniqueCode"].ToString())
{
//执行成功,完成其他任务
//....do.....
context.Response.Write(FeedbackState.Succeed.ToString()); }
else
{
context.Response.Write(FeedbackState.UniqueCodeError.ToString()); }
}
catch (Exception ex)
{
context.Response.Write(FeedbackState.Error.ToString());
}
finally
{
context.Response.End();
}
} public bool IsReusable {
get {
return false;
}
} }
1.C,下载地址返回顶部
作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

ashx-auth-黑色简洁验证码的更多相关文章

  1. 在ashx文件中制作验证码(使用session要继承IRequiresSessionState)

    必须继承System.Web.SessionState.IRequiresSessionState接口,才能实现Session读写! System.Web.SessionState的一些接口 IRea ...

  2. form组件注册ajax登录auth认证及验证码

    本项目采用django自带的数据库 项目文件 models.py from django.db import models from django.contrib.auth.models import ...

  3. aspx与ashx

    ashx在VS的中文版是新建“一般处理程序”,其实是一个实现类System.Web.IHttpHandler接口的类.而任何一个实现了IHttpHandler接口的类都能作为一个外部请求的目标程序.H ...

  4. Asp.Net验证码1

    验证码html调用 验证码:<input name="> <img src="CodeHandler.ashx" id="imgCode&qu ...

  5. ashx一般处理程序和HttpHandler

    asp.net项目中,使用.ashx的文件(一般处理程序)可以用于处理客户端发送来的请求,并将服务器端的处理结果返回给客户端.它能返回的类型可以是文本.或者图片.有时候,我们可以在项目中使用.cs的文 ...

  6. MVC之图片验证码

    MVC之图片验证码 controller中的action方法public ActionResult GetValidateCode() { ValidateCode vCode = new Valid ...

  7. asp.net 一般处理程序实现网站验证码

    使用VerifyCode.ashx一般处理程序生成验证码,实现如下: using System; using System.Drawing; using System.Web; using Syste ...

  8. ashx文件和aspx

    ashx文件和aspx文件有什么不同? 我们先新建一个ashx文件看看: <%@ WebHandler Language="C#" Class="Handler&q ...

  9. 【转载】Asp.Net生成图片验证码工具类

    在Asp.Net应用程序中,很多时候登陆页面以及其他安全重要操作的页面需要输入验证码,本文提供一个生成验证码图片的工具类,该工具类通过随机数生成验证码文本后,再通过C#中的图片处理类位图类,字体类,一 ...

随机推荐

  1. 利用hadoop自带程序运行wordcount

    1.启动hadoop守护进程 bin/start-all.sh 2.在hadoop的bin目录下建立一个input文件夹 JIAS-MacBook-Pro:hadoop- jia$ mkdir inp ...

  2. iframe标签用法详解(属性、透明、自适应高度)(总结)

    <iframe src="http://www.jb51.net" width="200" height="500"> 脚本之家 ...

  3. JDK8 学习

    http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html

  4. SDUT图结构练习——最小生成树

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=2144&cid=1186 这道题一开始是用prim算法做的,一直错一直错,后来问了帅郭改用 ...

  5. Oracle日期函数

    Oracle日期函数用于对Oracle数据库中的日期及时间进行处理. (1)ADD_MONTHS Oracle日期函数返回一个具有与所提供日期相差月份的日期,函数中给出了未来或以前的月份数.语法如下: ...

  6. 各种实用的js,bootstrap插件

    1.nivoSlider  非常优秀的Banner轮播插件 2.BootstrapTable 表格插件使用技巧 = http://www.cnblogs.com/landeanfen/p/497683 ...

  7. java登陆验证码与JS无刷新验证

    最近公司的项目的登陆模块由我负责,所以就做了个登陆小功能进行练手,其包括了用jQuery对用户名和密码进行不为null验证,和出于安全性考虑加了一个验证码的校验 别的不说先上代码 controller ...

  8. vc2005中没有classwizard这个命令

    vc2005中没有classwizard这个命令了 2005下怎么添加鼠标事件 vc2005中没有classwizard这个命令了 取代classwizard 中的添加消息映射,添加类,等等的功能主要 ...

  9. 61. Rotate List

    题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example:Giv ...

  10. 结巴分词标注兼容_ICTCLAS2008汉语词性标注集

    计算所汉语词性标记集Version 3.0制订人:刘群 张华平 张浩计算所汉语词性标记集... 10. 说明... 11. 名词 (1个一类,7个二类,5个三类) 22. 时间词(1个一类,1个二类) ...