验证码怎么结合用户名及密码登陆页面(搞了好久了还没解决呀!急)
bito 2004-08-14 10:41:01 验证码怎么结合用户名及密码登陆页面呀,我搞了好久都还没解决啊。。。
大侠们有无现成的源码呀,让我参考一下,谢谢。
我遇到的问题:
“用户名、密码、验证码”我都输入正确,可页面还是提示我输入的验证码错误呀,这是什么原因呀,有时点提交,还弹出一个对话框:“对不起,您还未登陆,请先登陆再进行操作”
登陆页面的后台源码:
using System;
using System.Data;
using System.Data.OleDb;
using System.Web.SessionState;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Login:Page
{
public Label lbl,lblShow;
public TextBox username,pwd,yz;
public Button login;
public Image Image1;
public void Page_Load(object sender, System.EventArgs e)
{
if (Session["VNum"]!=null)
{
string VNum=Session["VNum"].ToString();
Session.Abandon();
ViewState["VNum"]=VNum;
}
}
public void btn_Click(Object sender,EventArgs e)
{
if (yz.Text!=ViewState["VNum"].ToString())
{
lblShow.Text="<font color='red'>提示:验证码错误!</font>";
}
else
{
string sel="Select id From score Where username='"+username.Text.ToString()+"' and pwd='"+pwd.Text.ToString()+"'";
string conn="Provider=microsoft.Jet.OleDb.4.0;Data Source="+Server.MapPath("data.mdb");
OleDbConnection myconn=new OleDbConnection(conn);
myconn.Open();
OleDbCommand mycomm=new OleDbCommand(sel,myconn);
OleDbDataReader dr=mycomm.ExecuteReader();
if (dr.Read())
{
Session["username"]=username.Text;
Response.Redirect("welcome.aspx");
}
else
{
lbl.Text="用户名或是密码错误";
pwd.Text="";
}
}
}
}