怎样在visual C#中实现一个登陆验证,比如有一个textbox:t1一个t2,一个button,点击button如果t1是用户名,t2是密码,如果验证通过就显示ok,我知道这问题有点太弱了,但恳请帮忙

解决方案 »

  1.   

    在加一个Label1控件,
    在Button上添加Button的单击事件,
    指行如下代码:
      if (t1.Text =="name"&&t2.Text =="password")
    {
       Label1.Text ="OK";
       Redirect("index.aspx");
    }
      

  2.   

    private bool Validate(string sUid,string sUname)
    {
    //用以下查询语句时,数据库中不能有相同的UserId
    string strSql = "select UserId,UserName from Users where UserId='" + sUid + "'";
    SqlDataAdapter sqlDa = new SqlDataAdapter(strSql,GetConnection());
    DataTable dt = new DataTable();
    sqlDa.fill(dt);string strUserId = Convert.ToString(dt.Rows[0]["UserId"]);
    string strUserName = Convert.ToString(dt.Rows[0][UserName"]);
    if(sUid!=strUserId && sUname!=strUserName)
      return false;
    return true;
    }
    //在点出按钮是调用if(Validate(t1.Text,t2.Text))
    {
    //如果是真,你要做的相关操作
    }
    else
    {
    //如果是假,你要做的相关操作
    }
      

  3.   

    if (t1.Text =="name"&&t2.Text =="password")
    {
       Page.RegisterStartupScript("error",@"<script>alert('OK!');window.location.href='index.aspx';</script>");
       }
      

  4.   

    楼主加油 自己想想再google几下 应该就能解决 不难
      

  5.   

    只能给楼主思路,将两个Textbox中的数据通过SQL语句到数据库中与已有数据进行比较,如果比较结果相等则进入下一个页面,如果不相等提示密码错误或需要注册新用户。这是比较基础的部分,从网上或MSDN查下都可以找到很好的解决方法。
      

  6.   

    strsql="select Id from I_Operator where UserCode = '"+UserId.Text+"' and pass = '"+FHWL.Util.Security.EncryptPassWord(Password.Text)+"' and State = 0";
    SqlCommand sm= new SqlCommand(strsql,connection);
    SqlDataReader read = null;
    read = sm.ExecuteReader();
                    
    if(!read.Read())
    {
    count=count+1;
    if(count>3)
    {
    Response.Write("<script>alert('用户名密码不正确超过三次,请联系管理员!')</script>");
    Response.Write("<script>window.opener=null;window.close();</script>"); 
    }
    else
    Response.Write("<script>alert('对不起,用户名密码不正确,请重新输入!')</script>");
    read.Close();
    connection.Close();
    return;
    }
    else
    {
    Response.Redirect("xxxx.htm");  登陆成功
    }finally
    {
    if(conn!=null)
    conn.Close();
    if(read!=null)
    read.Close();if(connection!=null)
    connection.Close();
    }