C# 用 LDAP 验证用户名和密码

ldapBaseDnPath = "LDAP://localhost/DC=dc3,DC=dc2,DC=dc1"
// 'LDAP' 这4个字母必须大写
userName = "Name1"
password = "DoNotUseMe"

using (DirectoryEntry de = new DirectoryEntry(ldapBaseDnPath, userName, password)) {
    try {
        object connected = de.NativeObject;
        // 认证通过
    }
    catch {
        // 认证失败. 找原因
    }
}

 

你可能感兴趣的:(C#,Authentication,LDAP)