Authenticating against UIUC Active Directory (AD) using Python
So in a follow up to my earlier post, here is the equivalent code to authenticate against UIUC Active Directory using Python:
import ldap def authenticate(netid, password): server = "ldaps://ad.uiuc.edu:636" who = "CN="+netid+",OU=Campus Accounts,DC=ad,DC=uiuc,DC=edu" try: conn = ldap.initialize(server) ldap.set_option( ldap.OPT_X_TLS_DEMAND, True ) ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT,ldap.OPT_X_TLS_NEVER) result = conn.simple_bind_s(who,password) except ldap.LDAPError, e: return False conn.unbind() return True print authenticate("cemeyer2", "password")
That’s it. As mentioned in my earlier post, I’m pretty sure that any application that authenticates this way would be looked down upon by CITES since the application in question would potentially be able to sniff user login information, so please only use this code in a personal testing environment, not for a deployed application unless approved by people much higher up than me.