How to Authenticate LDAP in .NET

后端 未结 3 1636
甜味超标
甜味超标 2020-12-29 08:42

I would like to authenticate username and passwords for my application on a windows operating system with any directory service. For example it could be microsoft active di

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-29 09:41

    All this can be done with System.DirectoryServices.Protocols. If you create an LdapConnection to the directory you can use the service account to bind with, and then make a subsequent bind to authenticate the credentials.

    The service account is generally used to limit access to the authentication mechanism of the server. This way no random person on the street can try to auth with your LDAP server.

    Also, do you expect that each user will provide their distinguished name when logging in? With Active Directory, only the sAMAccountName is required, yet other providers like eDirectory and SunONE require the distinguished name for authentication.

    To perform this type of authentication, you would need to use the service account that is provided to authenticate to the server, perform a search for a user with the given username, and grab that users distinguished name. You can then authenticate using that distinguished name and the password that was provided.

    This will work for all LDAP systems, with the exception of Active Directory which will be happy with just the sAMAccountName.

提交回复
热议问题