Beispiel #1
0
        void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtUserName.Text))
            {
                MessageBox.Show("请输入用户名!");
                return;
            }
            if (string.IsNullOrEmpty(txtPassword.Password))
            {
                MessageBox.Show("请输入密码!");
                return;
            }

            string domain   = this.txtDomain.Text;//读取域信息
            string roleName = System.Configuration.ConfigurationManager.AppSettings["role"].ToString();

            string loginName  = txtUserName.Text;
            string userName   = "";
            string ADPath     = "LDAP://" + domain;;
            bool   isRole     = AdHelper.IsExistUser(ADPath, roleName, loginName, out userName);
            bool   isTrueUser = AdHelper.IsDomainUser(domain, loginName, txtPassword.Password);
            bool   result     = isRole && isTrueUser;

            //result = true;
            if (result)
            {
                CurrentLoginUserName = userName;
                this.DialogResult    = true;
            }
            else
            {
                if (!isRole)
                {
                    MessageBox.Show("用户不存在或者不属于指定的用户组!");
                }
                else if (!isTrueUser)
                {
                    MessageBox.Show("登录密码错误!");
                }
                return;
            }
        }