1

I was passing wrong credentials(password) in below code

conn = Connection(server, account_username, account_password, auto_bind=True)

and getting below error

ldap3.core.exceptions.LDAPBindError: automatic bind not successful - invalidCredentials

When I do the same without auto_bind argument in connection.

conn = Connection(server, account_username, account_password)
conn.bind()

conn was not throwing any error. conn.bind() is False. Help would be appreciated. Thanks

  • auto_bind isn't a flag. According to the [docs](https://ldap3.readthedocs.io/en/latest/connection.html): _auto_bind: automatically opens and binds the connection. Can be AUTO_BIND_NONE, AUTO_BIND_NO_TLS, AUTO_BIND_TLS_AFTER_BIND, AUTO_BIND_TLS_BEFORE_BIND._. Do these work for you? – tdelaney Apr 13 '22 at 17:49
  • No luck, they are not helpful even with the valid password. @tdelaney – Sandeep Konda Apr 13 '22 at 18:40
  • Tell us what you have tried and show logs or results and Read: https://stackoverflow.com/help/how-to-ask – jwilleke Apr 14 '22 at 08:13
  • Please check the edited post, I was trying to understand why Connection() method is not throwing any error when I passed a wrong password. @jwilleke – Sandeep Konda Apr 14 '22 at 10:56

1 Answers1

2

There are two ways to accomplish this:

  1. Check error raised during the last bind in the connection.last_error field.
server = ldap3.Server("LDAP_HOST", use_ssl=True)
connection = ldap3.Connection(
    server,
    "WRONG_LDAP_USERNAME",
    "WRONG_LDAP_PASSWORD"
)
connection.bind()
print(connection.last_error)

result

invalidCredentials
  1. Set argument raise_exceptions=True during initialization of the ldap3.Conneciton
server = ldap3.Server("LDAP_HOST", use_ssl=True)
connection = ldap3.Connection(
    server,
    "WRONG_LDAP_USERNAME",
    "WRONG_LDAP_PASSWORD",
    raise_exceptions=True
)
connection.bind()

result

dap3.core.exceptions.LDAPInvalidCredentialsResult: LDAPInvalidCredentialsResult - 49 - invalidCredentials - None - None - bindResponse - None