webform 图片验证码制作
界面:
1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Image ID="Image1" runat="server" ImageUrl="YZM.aspx" />
<asp:Button ID="Button1" runat="server" Text="验证" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
<script type="text/javascript">
var a = ;
//点击图片更换验证码
document.getElementById("Image1").onclick = function () {
this.setAttribute("src", "yzm.aspx?id=" + a);
a++;
}
</script>
后台:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Button1.Click += Button1_Click;
} void Button1_Click(object sender, EventArgs e)
{
string t1 = TextBox1.Text;
string t2 = Session["YZM"].ToString(); if (t1.ToUpper() == t2.ToUpper())
{
Label1.Text = "验证成功!";
}
else
{
Label1.Text = "验证失败!";
} }
}
验证码制作:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing; public partial class YZM : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Bitmap img = new Bitmap(, );//验证码图片大小
Graphics g = Graphics.FromImage(img);
Random r = new Random();
//背景色
List<Color> clist = new List<Color>();
clist.Add(Color.Yellow);
clist.Add(Color.Green);
clist.Add(Color.Blue);
clist.Add(Color.Pink);
clist.Add(Color.Orange);
clist.Add(Color.AliceBlue);
clist.Add(Color.Aqua);
clist.Add(Color.Cyan);
clist.Add(Color.DarkOliveGreen);
clist.Add(Color.Black); g.FillRectangle(new SolidBrush(clist[r.Next(, clist.Count)]), , , , ); for (int i = ; i < ; i++)
{
Color ccc = clist[r.Next(, clist.Count)];//随机颜色 Pen ppp = new Pen(new SolidBrush(ccc), r.Next(, ));//随机线条 g.DrawLine(ppp, new PointF(r.Next(, ), r.Next(, )), new PointF(r.Next(, ), r.Next(, )));
} //验证码
string all = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
string s = ""; for (int i = ; i < ; i++)
{
int a = r.Next(all.Length);//随机取数
s += all.Substring(a, );
} Session["YZM"] = s; g.DrawString(s, new Font("微软雅黑", ), new SolidBrush(Color.Red), new PointF(, )); img.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Png);
Response.End(); }
}
webform 图片验证码制作的更多相关文章
- webform:图片水印、验证码制作
一.图片水印 1:引命名空间System.Drawing; 前端代码 <div> <asp:FileUpload ID="FileUpload1" runat=& ...
- webform(十)——图片水印和图片验证码
两者都需要引入命名空间:using System.Drawing; 一.图片水印 前台Photoshuiyin.aspx代码: <div> <asp:FileUpload ID=&q ...
- Webform 文件上传、 C#加图片水印 、 图片验证码
文件上传:要使用控件 - FileUpload 1.如何判断是否选中文件? FileUpload.FileName - 选中文件的文件名,如果长度不大于0,那么说明没选中任何文件 js - f.val ...
- Atitit 图片 验证码生成attilax总结
Atitit 图片 验证码生成attilax总结 1.1. 图片验证码总结1 1.2. 镂空文字 打散 干扰线 文字扭曲 粘连2 1.1. 图片验证码总结 因此,CAPTCHA在图片验证码这一应用点 ...
- ASP.NET中图片验证码与js获取验证码的值
现在的程序中,为了防止用户恶意点击,我们一般都会加上验证,现在比较普遍的是加上图片验证码或者手机短信验证.验证码一般都是防机器不防人,有效的防止了恶意点击. 那么在webform中如何生成动态的图片验 ...
- 字符型图片验证码识别完整过程及Python实现
字符型图片验证码识别完整过程及Python实现 1 摘要 验证码是目前互联网上非常常见也是非常重要的一个事物,充当着很多系统的 防火墙 功能,但是随时OCR技术的发展,验证码暴露出来的安全问题也越 ...
- android图片验证码--自绘控件
自绘控件的内容都是自己绘制出来的 大致流程如下: 1.定义一个类继承view 使用TypedArray初始化属性集合 在view的构造方法中 有一个AttributeSet的参数 很明显是用来保存控件 ...
- Android-简单的图片验证码
Android-图片验证码生成1.为啥要验证码?图片验证码在网络中使用的是比较普遍的.一般都是用来防止恶意破解密码.刷票.论坛灌水.刷页等.2.怎样的验证码比较好?验证码的获取方式无非就两种,一种是后 ...
- 在mvc中实现图片验证码的刷新
首先,在项目模型(Model)层中建立一个生成图片验证码的类ValidationCodeHelper,代码如下: public class ValidationCodeHelper { //用户存取验 ...
随机推荐
- Debian8.3如何设置默认不启动Gnome
最近又光荣的回归了debian的怀抱,其实我就是跟风,现在做传媒平时也用不到多么高深的计算机知识,纯粹自己瞎鼓捣……嘿嘿,我相信有很多像我一样的人,刚刚装上了debian可以在同事面前华丽丽的装了一逼 ...
- CI 扩展 Service
CI 扩展 Service 说明 CodeIgniter是一套典型的MVC框架,M负责数据,C负责交互,V负责视图,但是随着业务逻辑越来越复杂, 必然会涉及到一些列操作过程,例如用户下订单,就会存在校 ...
- C# 金钱 小写转大写的算法
调用 ConvertMoney的ConvertMoneyToWords(decimal money)方法即可 using System; using System.Collections.Generi ...
- jquery样式篇
1.jquery: 1.1简介 jquery是一个轻量级的javascript库.版本号分1.x版本和2.x版本,2.x版本不再支持IE6 7 8,而更好的支 持移动端开发. 每一个版本分为开发版和压 ...
- css初始化代码
最近老有新项目开发,一直在找存留的CSS初始化代码,索性放到这里备份下, @charset "utf-8"; /* -------------------------------- ...
- linux部署pxe+kickstart批量安装linux操作系统
环境 系统 centos6.6 无图形界面 ip 192.168.2.1 系统 centos7.2 有图形界面 以下命令在centos6.6上执行 1. yum -y install dhcp* tf ...
- iOS Universal Links(通用链接)
公司的运维,发现最近大量的请求 /.well-known/apple-app-site-association这个文件,造成了大量的404,可是这是谁请求的呢? 其实是苹果从iOS9.3开始更改了通用 ...
- IIS6.0 web.config
IIS6.0环境下,要把托管管道模式 改为:经典. <?xml version="1.0" encoding="UTF-8"?> <confi ...
- Object-c 内存管理
内存管理 主要内容 1.内存管理的概念 2.引用计数 3.如何持有对象所有权 4.自动释放池 5.@property的使用 什么是内存管理 内存管理是关于如何管理对象生 ...
- C++各种进制的转换
/* @author:CodingMengmeng @theme:各种进制之间的转换 @time:2017-1-6 21:39:08 @blog:http://www.cnblogs.com/codi ...