def _bind_ldap(self, ldap, con, username, password):
try:<EOL><INDENT>if self.auth_ldap_bind_user:<EOL><INDENT>self._bind_indirect_user(ldap, con)<EOL>user = self._search_ldap(ldap, con, username)<EOL>if user:<EOL><INDENT>log.debug("<STR_LIT>".format(user))<EOL>username = user[<NUM_LIT:0>][<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>log.debug("<STR_LIT>".format(username, "<STR_LIT>"))<EOL>if self.auth_ldap_username_format:<EOL><INDENT>username = self.auth_ldap_username_format % username<EOL><DEDENT>if self.auth_ldap_append_domain:<EOL><INDENT>username = username + "<STR_LIT:@>" + self.auth_ldap_append_domain<EOL><DEDENT>con.bind_s(username, password)<EOL>log.debug("<STR_LIT>".format(username))<EOL>return True<EOL><DEDENT>except ldap.INVALID_CREDENTIALS:<EOL><INDENT>return False<EOL><DEDENT>
Private to bind/Authenticate a user.
If AUTH_LDAP_BIND_USER exists then it will bind first with it,
next will search the LDAP server using the username with UID
and try to bind to it (OpenLDAP).
If AUTH_LDAP_BIND_USER does not exit, will bind with username/password