How do I authenticate against AD using Python + LDAP. I\'m currently using the python-ldap library and all it is producing is tears.
I can\'t even bind to perform a
I had the same issue, but it was regarding the password encoding
.encode('iso-8859-1')
Solved the problem.
Use a Distinguished Name to log on your system."CN=Your user,CN=Users,DC=b2t,DC=local"
It should work on any LDAP system, including AD
I see your comment to @Johan Buret about the DN not fixing your problem, but I also believe that is what you should look into.
Given your example, the DN for the default administrator account in AD will be: cn=Administrator,cn=Users,dc=mydomain,dc=co,dc=uk - please try that.
I was missing
l.set_option(ldap.OPT_REFERRALS, 0)
From the init.
If you are open to using pywin32, you can use Win32 calls from Python. This is what we do in our CherryPy web server:
import win32security
token = win32security.LogonUser(
username,
domain,
password,
win32security.LOGON32_LOGON_NETWORK,
win32security.LOGON32_PROVIDER_DEFAULT)
authenticated = bool(token)
if you have Kerberos installed and talking to AD, as would be the case with, say, Centrify Express installed and running, you might just use python-kerberos. E.g.
import kerberos
kerberos.checkPassword('joe','pizza','krbtgt/x.pizza.com','X.PIZZA.COM')`
would return True a user 'joe' has password 'pizza' in the Kerberos realm X.PIZZA.COM. (typically, I think, the latter would be the same as the name of the AD Domain)