Active Directory Authentication

Stephan Diehl stephan.diehl at
Fri May 5 15:23:05 CEST 2006

On Fri, 05 May 2006 05:39:08 -0700, D wrote:

> Is it possible to have Python authenticate with Active Directory?
> Specifically what I'd like to do is have a user enter a
> username/password, then have Python check the credentials with AD - if
> what they entered is valid, for example, it returns a 1, otherwise a
> 0..  Thanks!

It's possible and you need the python-ldap package for it.
The actual authentication will look like (simplified):

def authenticate(user='',passwd=''):
    dn = find_user_dn(user)
        l =
        l.protocol_version = ldap.VERSION3
        return True
    except ldap.LDAPError:
        return False
obviously, you need to supply some function 'find_user_dn' that maps
the user to its DN.

More information about the Python-list mailing list