Answer the question
In order to leave comments, you need to log in
Python authentication in Active Directory?
It is necessary to make user authentication in AD in python. I decided to use ldap lib, only there is one small BUT
- with incorrect data, I get a lapel-turn from the server
- in the case of correct data or empty username = '', password = '' everything is OK
, how so?
Why does it take empty input?
#!/usr/bin/env python
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, 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"
name = '[email protected]'
password = 'Qwerty12345'
name = ''
password = ''
result = authenticate('192.168.1.33', name, password)
print result
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question