c# winform active directory: acces to another form if login succes

前端 未结 4 2014
礼貌的吻别
礼貌的吻别 2021-01-26 07:56

i want to create a control from a form where i have login textbox and password textbox, and login button. when i will enter the active directory account name and its password i

4条回答
  •  伪装坚强ぢ
    2021-01-26 08:23

    i solved what i was looking for

    private void btnLogin_Click(object sender, EventArgs e)
            {
    
                try
                {
                    LdapConnection connection = new LdapConnection("AD");
                    NetworkCredential credential = new NetworkCredential(txtboxlogin.Text, txtboxpass.Text);
                    connection.Credential = credential;
                    connection.Bind();
    
                   MessageBox.Show("You are log in");
                   Hide();
                   if (txtboxlogin.Text == "WantedAdminUser")
                   {
    
                   using (AdminForm form2 = new AdminForm())
                       form2.ShowDialog();
                   Show(); 
                   }
                   else
                   {
                       using (user userform = new user())
                           userform.ShowDialog();
                       Show();
                   }
    
                }
                catch (LdapException lexc)
                {
                    String error = lexc.ServerErrorMessage;
                    MessageBox.Show("error account or password.");
                }
                catch (Exception exc)
                {
                    MessageBox.Show(Convert.ToString(exc));
                }
    

提交回复
热议问题