网游登陆账号的密保卡
验证卡片
验证登陆界面
请大家先看一下效果,这个是我最初做的,大家有兴趣的话可以延伸一下功能,做成像网易密保卡一样自动生成,
不知道大家玩过征途没有,游戏登陆的时候需要进行一下验证
那个验证程序我一直想做,但这段忙抽不出时间,有做出来的朋友可否共享一下
以下是参考图
生成验证码的页面.cs文件中的代码
Code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//this.CreateCheckCodeImage(GenerateCheckCode());
yanzheng();
this.image(Label1.Text);
}
//通过二维数组产生验证码
public void yanzheng()
{
char[] col_arr ={ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I' };
char[] row_arr ={ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K' };
string[,] myArray; // 创建数组
myArray = new string[,] { {"17","19","T1","53","V8","16","H2","K3","Q1"},
{"U6","36","R7","5S","34","T2","V6","3X","56"},
{"A5","J3","D9","2F","K4","G7","5C","I4","15"},
{"49","P7","R9","89","C4","7F","T3","X5","V1"},
{"V2","1C","63","8G","7M","M9","7V","K6","P2"},
{"45","6P","R8","4J","J5","99","J3","6H","J1"},
{"59","S9","A4","55","9M","H1","6N","88","6L"},
{"7A","A9","L5","R2","19","A6","L4","T6","72"},
{"14","3D","7Z","81","J6","6C","9J","5Z","M9"},
{"K7","5J","4M","5P","27","R1","A7","86","6M"},
{"K8","46","7X","77","9D","2D","9K","12","78"}};
try
{
Random rdm = new Random(); // 实例化一个生成器
int index = rdm.Next(0, 9);//列的索引
int index1 = rdm.Next(0, 11);//行的索引
Session["lie"] = row_arr[index1];
Session["hang"] = col_arr[index];
Session["yzm"] = myArray[index1, index];
for (int i = 0; i < 11; i++)
{
for (int j = 0; j < 9; j++)
{
Response.Write(myArray[i, j] + ",");
}
Response.Write("<br>");
}
Label1.Text = Session["lie"].ToString();
Label1.Text += Session["hang"].ToString(); //给显示验证码的label赋值
Response.Write(Session["yzm"].ToString());//测试产生的结果
//Session["zong"] = Label1.Text.ToString();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
private void image(string neirong)
{
if (neirong == null || neirong.Trim() == String.Empty)
return;
System.Drawing.Bitmap image = new System.Drawing.Bitmap((int)Math.Ceiling((neirong.Length * 30.5)), 35);
Graphics g = Graphics.FromImage(image);
try
{
//生成随机生成器
Random random = new Random();
//清空图片背景色
g.Clear(Color.White);
//画图片的背景噪音线
for (int i = 0; i < 25; 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.Silver), x1, y1, x2, y2);
}
Font font = new System.Drawing.Font("Arial", 20, (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.Blue, Color.DarkRed, 1.2f, true);
g.DrawString(neirong, font, brush, 2, 2);
//画图片的前景噪音点
for (int i = 0; i < 100; 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();
}
}
}
登陆页面.cs文件中的代码
Code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
if (TextBox1.Text != "" || TextBox1.Text != null)
{
DelSQLStr(TextBox3.Text.Trim().ToString());
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "" || TextBox1.Text != null)
{
if (string.Equals(Session["yzm"].ToString(), this.TextBox1.Text))
{
Response.Write("登陆正确!");
}
else
{
Response.Write("登陆不正确!");
}
}
else
{
Response.Write("请输入验证码");
}
}