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 { //用户存取验 ...
随机推荐
- Reverse Core 第二部分 - 13章 - PE文件格式
@date: 2016/11/24 @author: dlive PE (portable executable) ,它是微软在Unix平台的COFF(Common Object File For ...
- main 返回值
int main() 在c中表示返回值时int:也可以不明确给出返回值,默认为int:()表示接受任何参数,main(void)表示不接受任何参数.main(),int main(),main(voi ...
- c/c++ string
string类的定义.操作. #include<iostream> #include<string> using namespace std; int main() { // ...
- Android Studio accelerator key(shortcut)& Basic knowledge
shift + F6 重构(选文件,ok->下面的控制台,do refactor option + return 快速修复 Activity@Extra() Intent: @FragmentA ...
- centos 安装pip,使用pip安装django
python版本要2.7.x以上版本,若未安装python执行以下命令安装: wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgz ...
- androidstdio偶遇一
android的错误 今天在安装androidstdio的过程中产生了遇到了一个错误(之前一直没有重新安装,因为觉得麻烦,但是电脑慢成狗了,只好重新安装....)那么现在步入正题. 首先安装的 ...
- expect
#!/usr/bin/expect -fset ipaddr "192.168.5.4"set passwd "123qwe"set timeout 30 sp ...
- C# 操作excel单元格居中
C# 操作excel //导出Excel private void ExportExcel(string fileName, System.Data.DataTable myDGV, s ...
- [Android Pro] Android开发实践:自定义ViewGroup的onLayout()分析
reference to : http://www.linuxidc.com/Linux/2014-12/110165.htm 前一篇文章主要讲了自定义View为什么要重载onMeasure()方法( ...
- MVC之Model转Json
在开发中,有时我们需要在View层中拿到Model返回的数据并且是一个Json对象,那么我们就可以利用Newtonsoft.Json.JsonConvert.SerializeObject(Model ...