1. 程式人生 > >C#學習筆記-域用戶認證(一)

C#學習筆記-域用戶認證(一)

byte name urn validate finally tostring code date geb

        public Boolean ValidateDomainUser(string Domain, string UserName, string Password)
        {
            DirectoryEntry entry = new DirectoryEntry(Domain, UserName, Password);
            try
            {
                string objectSid = (new SecurityIdentifier((byte[])entry.Properties["
objectSid"].Value, 0).Value);//如果賬號不對則會拋出異常 return true; } catch { return false; } finally { entry.Dispose(); } } //代碼調用,LDAP一定要大寫。 MessageBox.Show(ValidateDomainUser("
LDAP://域控的IP地址/DC=ha-ad,DC=net", "evan", "evan的密碼").ToString());

C#學習筆記-域用戶認證(一)