本帖最后由 lan_wang 于 2010-11-25 08:58:43 编辑

解决方案 »

  1.   


    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
              bool Authenticated = false;
              Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
              e.Authenticated = Authenticated;
              if (Authenticated == true)
              {
                        Response.Redirect("Home.aspx");
              }
    }
    private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
    {
              bool boolReturnValue = false;
              // Insert code that implements a site-specific custom 
              // authentication method here.
              // This example implementation always returns false.
              //这里是你数据库的信息
              string strConnection  = "server=dtpxp-skumari;database=master;uid=sa;pwd=;";
              SqlConnection Connection = new SqlConnection(strConnection);
              String strSQL = "Select * From Employee";
              SqlCommand command =new SqlCommand(strSQL, Connection);
              SqlDataReader Dr;
              Connection.Open();
              Dr=command.ExecuteReader();
              while (Dr.Read())
              { 
                        if ((UserName == Dr["name"].ToString()) & (Password == Dr["Password"].ToString()))
                        {
                                 boolReturnValue = true;
                        } 
                        Dr.Close();
                        return boolReturnValue;
              }

      

  2.   

    最简单的一种 string cmdtxt="select id from [ENTUserAccount] where username='"+用户名 +"'" and password='"+密码+"'";
    sqlcommand cmd=new sqlcommand(str,con);
    con.open();object o=cmd.executeScalar();con.close()
    if(o==DBnull.value)
    return false;//登陆失败 账号密码错误
    else
    return true;//账号密码正确 返回ture
    然后你可以在页面调用这个方法,如果返回值是true 你就可以跳转页面,否则就不跳转。
    但是最好的登陆方法使用存储过程,安全
      

  3.   

    谢谢各位!
    二楼三楼的意思我明白,实现后自然就能OK。
    但我刚刚才注意到,那个用户表中居然没有“密码”这一字段……真是晕倒
    看来只有把那本书全部看完后再来请教各位
    3KS!