【问题标题】:how can check the username and password in c#? [closed]c#中如何查看用户名和密码? [关闭]
【发布时间】:2014-01-30 09:42:08
【问题描述】:

在c#的登录页面中,如何检查用户名和密码是否与sqlserver中的用户名和密码匹配以登录下一页? 我不想使用存储过程!

【问题讨论】:

  • O.o 请尝试一下,如果您遇到任何错误,您可以在此处发布
  • 请出示您的代码。你被困在哪里了..?
  • 请查看以下链接。它会帮助你。 codeproject.com/Articles/408306/…

标签: c# sql-server


【解决方案1】:

这样试试

 protected void loginButton_Click(object sender, EventArgs e)
{

    SqlConnection con = new SqlConnection();
    con.ConnectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=University;Integrated Security=True;Pooling=False";


    Int32 verify;
    string query1 = "Select count(*) from Login where ID='" + idBox.Text + "' and Password='" + passwordBox.Text + "' ";
    SqlCommand cmd1 = new SqlCommand(query1, con);
    con.Open();
    verify = Convert.ToInt32(cmd1.ExecuteScalar());
    con.Close();
    if (verify > 0)
    {
        Response.Redirect("succesful.aspx");
    }
    else
    {
        Response.Redirect("unsuccesful.aspx",true);
    }

}

但是你需要使用存储过程来避免SQL INJECTION

【讨论】:

  • 不,您不需要使用存储过程。只需使用准备好的语句。
猜你喜欢
  • 2014-02-21
  • 1970-01-01
  • 2013-06-05
  • 1970-01-01
  • 2019-03-03
  • 2016-06-22
  • 1970-01-01
  • 2016-09-24
  • 1970-01-01
相关资源
最近更新 更多