loner_li web开发中登录与注册 常用的验证码(无刷新的哦)
来源:互联网 发布:乐乎lofter手机版 编辑:程序博客网 时间:2024/05/21 17:44
//前台
<script language="javascript" type="text/javascript">
function fresh() {
var randomnum = Math.random();
var getimagecode = document.getElementById("codeimage");
getimagecode.src = "ValidateImage.aspx? " + randomnum;
}
</script>
<div><img id="codeimage" src="ValidateImage.aspx?,Math.random()" />
<asp:TextBox ID="txtValidateCode" runat="server" Width="55px" MaxLength="4"></asp:TextBox>
<a href="javascript:fresh()" style="font-size: 12px; color: Green">看不清</a></div>
Validateimage.aspx页面是生成图片
.cs文件
private void Page_Load(object sender, System.EventArgs e)
{
this.CreateCheckCodeImage(RndNum());
}
private string RndNum()
{
int number;
char code;
string checkCode = String.Empty;
System.Random random = new Random();
for (int i = 0; i < 4; i++)
{
number = random.Next();
if (number % 2 == 0)
code = (char)('0' + (char)(number % 10));
else
code = (char)('A' + (char)(number % 26));
checkCode += code.ToString();
}
Response.Cookies.Add(new HttpCookie("yzmcode", checkCode));
return checkCode;
}
private void CreateCheckCodeImage(string checkCode)
{
if (checkCode == null || checkCode.Trim() == String.Empty)
return;
System.Drawing.Bitmap image = new System.Drawing.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 < 20; 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.Aqua), x1, y1, x2, y2);
}
Font font = new System.Drawing.Font("Arial", 12, (System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic));
System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.BlueViolet, Color.BlueViolet, 1.2f, true);
g.DrawString(checkCode, font, brush, 2, 2);
//画图片的前景噪音点
for (int i = 0; i < 50; i++)
{
int x = random.Next(image.Width);
int y = random.Next(image.Height);
image.SetPixel(x, y, Color.FromArgb(random.Next()));
}
//画图片的边框线
g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
Response.ClearContent();
Response.ContentType = "image/Gif";
Response.BinaryWrite(ms.ToArray());
}
finally
{
g.Dispose();
image.Dispose();
}
}
- loner_li web开发中登录与注册 常用的验证码(无刷新的哦)
- loner_li AJax 实现数据的 无刷新分页 实例(引用web服务文件和存储过程)
- loner_li AJax 无刷新 省市县三级联动(最终版)(webservice+三层)Html版和 有刷新的 web版 (2)
- web实现验证码和简单的登录注册
- 注册无刷新验证
- 登录、注册的验证码
- flask-web开发中登录和注册功能的实现
- loner_li AJax 无刷新 省市县三级联动(webservice+sqlhelp)客户端控件版和 有刷新 web版
- java web编程中 struts2+hibernate 实现B2C电子商务网站的登录 、注册中验证码的实现(源码精简版)
- loner_li Asp.net 中常用的sqlhelp.cs 类文件
- 验证码无刷新的方法。
- 注册界面无刷新验证
- struts2+hibernate 实现B2C电子商务网站的登录 、注册中验证码的实现(源码)
- struts2+hibernate 实现B2C电子商务网站的登录 、注册中验证码的实现(源码)
- struts2+hibernate 实现B2C电子商务网站的登录 、注册中验证码的实现(源码)
- struts2+hibernate 实现B2C电子商务网站的登录 、注册中验证码的实现(源码)
- 无验证图片的注册
- loner_li 委托与事件 复习实例之 ‘注册信息写入记事本’(web服务控件)
- 一些jar包的作用 --学习了
- HDU 4344 大数分解
- git邮件发送
- Jslint、Jshint代码检查工具
- Unity3D启动外部exe
- loner_li web开发中登录与注册 常用的验证码(无刷新的哦)
- uboot-----borad.c . .
- 最近做的简单的编程练习
- makefile中wildcard notdir patsubst的简单介绍
- uboot中main_loop分析 .
- 如何改变对话框的背景颜色
- 再谈cacheAsBitmap
- System.map介绍 .
- jquery写的东西记得要加";"分号,要不然会出现不一样的结果