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

资讯 驱动中国 若水 13,515 次阅读 0 条评论
分享 Q

 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();
   }

-
版权声明:本文由驱动中国整理发布,转载需注明出处与原文链接。如有疑问请联系 editor@qudong.com
本文价值 成为第一个评分的人
登录后为本文打分
网友评论0 条评论
正在回复 的评论取消
评论加载中…
🔐

登录后参与互动

评论、点赞均可赚积分
连续签到、邀请好友也有奖励 🎁

电脑端: 微信扫码登录 微信内: 一键登录

微信扫一扫

打开微信「扫一扫」,分享本文到朋友圈或好友