title: django-auth-ldap failed authentication
body: <p>I'm trying to use <a href="https://pythonhosted.org/django-auth-ldap/" rel="noreferrer">Django-Auth-Ldap</a> in my project (Django 1.6, Python 2.7) but it is not working.</p>
  
  <p>My active Directory shema is:</p>
  
  <p><a href="https://i.stack.imgur.com/GitJR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/GitJR.png" alt="enter image description here"></a></p>
  
  <ol>
  <li><p>I've tested the connection on the cmd line by installing the ldap-utils package</p>
  
  <pre><code>sudo apt-get install ldap-utils
  
  ldapsearch -H ldap://domain.com -D "ou=Resources,ou=Company, dc=domain,dc=com" -U "user_name" -w "user_password" -v -d 1
  </code></pre></li>
  </ol>
  
  <p>The connection test works fine.</p>
  
  <ol start="2">
  <li><p>I am using below code to test python-ldap connection from the shell:</p>
  
  <pre><code>import ldap
  
  con = ldap.initialize('ldap://domain.com')
  
  con.simple_bind_s('User_mail', 'User_password')
  
  results = con.search_s('ou=Users,ou=Resources,ou=Company,dc=domain,dc=com', ldap.SCOPE_SUBTREE, "(cn=User_name)")
  </code></pre></li>
  </ol>
  
  <p>python-ldap connection works fine.</p>
  
  <ol start="3">
  <li>My problem is how to authenticate AD users from my django login interface?</li>
  </ol>
  
  <p>settings.py:</p>
  
  <pre><code>import ldap 
  from django_auth_ldap.config import LDAPSearch
  
  # The URL of the LDAP server.
  AUTH_LDAP_SERVER_URI = "ldap://domain.com"
  AUTH_LDAP_BIND_DN = "cn='User_name',ou=Resources,ou=Company,dc=domain,dc=com"   
  AUTH_LDAP_BIND_PASSWORD = "User_password"
  AUTH_LDAP_USER_SEARCH = LDAPSearch("ou=Users,ou=Resources,ou=Company,dc=domain,dc=com",ldap.SCOPE_SUBTREE, "(cn=%(user)s)")    
  AUTH_LDAP_GLOBAL_OPTIONS = { ldap.OPT_REFERRALS : False }
  
  AUTHENTICATION_BACKENDS = (
  'django_auth_ldap.backend.LDAPBackend',
  'django.contrib.auth.backends.ModelBackend',
  )
  </code></pre>
  
  <p>views.py:</p>
  
  <pre><code>from django_auth_ldap.backend import LDAPBackend
  auth = LDAPBackend()
  user = auth.authenticate(username="User_name", password="User_password")
  </code></pre>
  
  <p>In the file django-ldap-debug.log I have this error:</p>
  
  <pre><code>Caught LDAPError while authenticating User_name: INVALID_CREDENTIALS({'info': '80090308: LdapErr: DSID-0C0903A9, comment: AcceptSecurityContext error, data 52e, v1db1', 'desc': 'Invalid credentials'},)
  </code></pre>