title: How can I verify user and password using Python ldap3 via OpenLdap?
body: <p>For a django project, I designed a different login page. The users here will log in via openldap.</p>
  <p>I can access users' full information with their uid id, but I could not find how to verify the password.</p>
  <p>Do I need to hash the user's password and compare it with the password on ldap? Isn't there any other method? Thank you</p>
  <pre><code>from ldap3 import Server, Connection, ALL, SUBTREE
  from ldap3.core.exceptions import LDAPException, LDAPBindError, LDAPSocketOpenError
  from ldap3.utils.conv import escape_filter_chars
  
  ldap_server_uri=f&quot;ldap://xxx:389&quot;
  ldap_base = 'dc=xx,dc=xx,dc=xx'
  
  def ldap(uid,password):
      try:     
          ldap_server = Server(ldap_server_uri, get_info=ALL)
          ldap_connection = Connection(ldap_server, user = 'uid=admin,ou=xx,dc=xx,dc=xx',password='adminpassword')
          if ldap_connection.bind() == True:
              if ldap_connection.search(search_base=ldap_base, search_filter=f'(uid={uid})',search_scope = SUBTREE, attributes=['uid']) == True:
                  ent = ldap_connection.entries[0]
                  entry = {'uid': ent['uid']}
                  ldap_connection.unbind()
                  return entry
              else:
                  return None
      except LDAPSocketOpenError:
          print('Unabled to connect to the LDAP server!')
          return None
  </code></pre>