Authentication with ldap
Completion requirements
The following python script demonstrates the authentication with ldap:
import ldap
def authenticate(address, username, password):
conn = ldap.initialize('ldap://' + address)
conn.protocol_version = 3
conn.set_option(ldap.OPT_REFERRALS, 0)
try:
result = conn.simple_bind_s(username, password)
except ldap.INVALID_CREDENTIALS:
return "Invalid credentials"
except ldap.SERVER_DOWN:
return "Server down"
except ldap.LDAPError as e:
if type(e.message) == dict and e.message.has_key('desc'):
return "Other LDAP error: " + e.message['desc']
else:
return "Other LDAP error: " + e
finally:
conn.unbind_s()
return "Succesfully authenticated"
print(authenticate('192.168.10.254', 'administrator@trainingX.net', 'yourPassword'))
Source: https://blog.thomastoye.be/python-ldap-authentication-with-microsoft-active-directory-46661bebc483Last modified: Tuesday, 17 December 2019, 7:10 PM