ChuckWoodraska
2/2/2017 - 5:57 PM

LDAP authentication test with Python 3.

LDAP authentication test with Python 3.

import ldap3 as ldap

SERVER_NAME = 'ldap.example.com'
DN = 'EXAMPLEDOMAIN'
USERNAME = 'user'
PASSWORD = 'password'

server = ldap.Server(SERVER_NAME)
connection = ldap.Connection(server, user='{}\\{}'.format(DN, USERNAME), password=PASSWORD)
connection.open()
if connection.bind():
    print('Authenticated!')
else:
    print('Not Authenticated')
    print(connection.result)