用户通过SQL以多个权限级别登录

时间:2019-01-20 15:10:13

标签: c# mysql login

我想要具有多个权限级别的用户登录,我的SQL具有Perm_type列 我想当Perm_type为1时显示管理员,Perm_type为2时显示职员

我不知道如何添加代码来检查Perm_type

SQL

我的代码是

  public Login_form()
    {
        InitializeComponent();

        /*initialize connection*/
        con = new MySqlConnection("Server=localhost;Database=demo;user=demouser;Pwd=demopassword;SslMode=none");

    }
    private void Login_btn_Click(object sender, EventArgs e) //Log In Button
    {
        string user = id_txt.Text;
        string pass = Pwd_txt.Text;
        cmd = new MySqlCommand();
        con.Open();
        cmd.Connection = con;
        cmd.CommandText = "SELECT * FROM demo_login where id='" + id_txt.Text + "' AND password='" + Pwd_txt.Text + "'";
        dr = cmd.ExecuteReader();

        if (dr.Read())
        {

                Administrator new_Form = new Administrator();
            new_Form.Show();

        }
        else
        {
            MessageBox.Show("Invalid Login please check username and password");
        }
        con.Close();
    }

0 个答案:

没有答案