我如何实际登录用户

时间:2018-12-15 19:56:16

标签: c#

我对C#还是很陌生,我正在登录系统上工作。该程序可以验证用户信息,但是我不知道您应该如何登录用户。因为现在您会收到一条成功消息,仅此而已。 以及如何将用户重定向到应用程序的其余部分。这是一个本机应用程序,我能找到的只是关于如何在c#.net的asp.net instad中重定向的信息。

private void button1_Click(object sender, EventArgs e)
    {
        string user = textBox1.Text;
        string pwd = textBox2.Text;
        MySqlConnection conn = new MySqlConnection("server = localhost; user id = root; database = bot");
        MySqlDataAdapter sda = new MySqlDataAdapter("select count(*) from license where user = '" + textBox1.Text + "' and pwd = '" + textBox2.Text + "'", conn);
        DataTable dt = new DataTable();
        sda.Fill(dt);
        if (dt.Rows[0][0].ToString() == "1")
        {

            MessageBox.Show("Successful login!", "info", MessageBoxButtons.OK, MessageBoxIcon.Information);


        }
        else
        {
            MessageBox.Show("Info is not valid", "alter", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }

1 个答案:

答案 0 :(得分:-2)

您只需要定义该类的对象,并将Show();用于ASP.NET后使用this.Hide();

为提高登录表单的安全性,应阅读以下内容以防止SQL注入攻击:https://www.codeproject.com/Articles/9378/%2FArticles%2F9378%2FSQL-Injection-Attacks-and-Some-Tips-on-How-to-Prev

https://www.mikesdotnetting.com/article/113/preventing-sql-injection-in-asp-net

用于会话设置

How to set security on Login Page in asp.net

用于加密:

C# encrypted Login

Response.Redirect("Dashboard.aspx")

对于ASP.NET

  private void button1_Click(object sender, EventArgs e)
    {
        string user = textBox1.Text;
        string pwd = textBox2.Text;
        MySqlConnection conn = new MySqlConnection("server = localhost; user id = root; database = bot");

 string query = "Select * from license Where user = '" + textBox1.Text.Trim() + "' and pwd = '" + textBox2.Text.Trim() + "'";
            SqlDataAdapter sda = new SqlDataAdapter(query, conn );
            DataTable dtbl = new DataTable();
            sda.Fill(dtbl);
            if (dtbl.Rows.Count == 1)
            {    //change the name of the form depend on the form that you need to show.
                frmMain objFrmMain = new frmMain();
                this.Hide();
                objFrmMain.Show();
            }
            else
            {
                MessageBox.Show("Check your username and password");
            }

    }

从此处下载代码:https://drive.google.com/drive/folders/17KvHSTJvvD5jmcufr35-V8TV67pHL7D8