黑马程序员技术交流社区
标题:
怎样改把这个验证码用上?
[打印本页]
作者:
李礼彬
时间:
2013-5-17 22:52
标题:
怎样改把这个验证码用上?
类定义:
#region 验证码
public string sjnum(int n)
{
string strchar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z";
string[] VcArray = strchar.Split(',');
string VNum = "";
int temp = -1;
Random rand = new Random();
for (int i = 1; i < n + 1; i++)
{
if (temp != -1)
{
rand = new Random(i * temp * unchecked((int)DateTime.Now.Ticks));
}
int t = rand.Next(61);
if (temp != -1 && temp == t)
{
return sjnum(n);
}
temp = t;
VNum += VcArray[t];
}
return VNum;
}//登录验证
#endregion
登录界面代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("index.aspx");
}
protected void Button1_Click(object sender, EventArgs e)
{
gly ds1 = new gly();
if (TextBox1.Text == "" || TextBox2.Text == "")
{
gly.infoAndRedirect("登录名和密码不能为空!", "login.aspx");
}
else
{
if (TextBox3.Text == Label1.Text)
{
ds1.gzh = TextBox1.Text;
ds1.gmm = TextBox2.Text;
int flag = ds1.glylog();
if (flag == 1)
{
gly.infoAndRedirect("登录成功!", "../admin/newsdatas.aspx");
}
else
{
gly.infoAndRedirect("信息有误!", "login.aspx");
}
}
}
}
复制代码
登录的代码里改,谢谢!
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2