搜索|收藏|地图|订阅|图片|论坛|商城

典型的asp.net登陆验证代码

来源:龙腾软件教程网 编辑:若水 时间:2008-05-08
 void Page_Load(object sender, System.EventArgs e)
  {
   string username=Request.Form.Get("UserName");
   string pwd=Request.Form.Get("PassWord");
   ConnectSql(username,pwd);
  }
  private void ConnectSql(string username,string pwd)
  {
   IDbConnection conn = null;
   try
   {
    conn = new SqlConnection("server=192.168.0.220;uid=sa;pwd=;database=text");
    conn.Open();
    string mySel="select * from [user] where name="+"'"+username+"'";
    SqlCommand com = new SqlCommand(mySel, (SqlConnection)conn);
    SqlDataReader reader = com.ExecuteReader();
    if(!reader.HasRows)
    {
     Response.Redirect("index.aspx?error=用户名错误");
    }
    else
    {
     while(reader.Read())
     {
      if(pwd!=reader.GetString(2))
       Response.Redirect("index.aspx?error=密码错误");
      else
       Response.Redirect("Main.html");
     }
    }
   }
   catch(SqlException)
   {
    Response.Write("在打开连接时出现连接级别的错误!");
   }
   finally
   {
    if(conn != null)
     conn.Close();
   }
-
最新评论共有 0 位网友发表了评论
发表评论
评论内容:不能超过250字,需审核,请自觉遵守互联网相关政策法规。
用户名: 密码:
匿名?