2

I am authenticating with ldap and have it all working when the correct credentials are put in however if the user is not valid or the password is incorrect the ldap_bind gives the following warning:

Warning: ldap_bind(): Unable to bind to server: Invalid credentials...

This means the following line which i think should check if the ldap_bind has worked is being executed when it should fail:

$ldapbind = ldap_bind($ldapconn,"uid=$username,cn=users,dc=abc,dc=net", "$password");
if ($ldapbind) {

Do i need to change the if statment so the warning for invalid credentials results in a fail and it moves onto the else statment ? I have tried the following but it hasn't made a difference.

if (($ds) !== false )
a.smith
  • 305
  • 2
  • 14

1 Answers1

2

You can try:

$ldapbind = @ldap_bind($ldapconn,"uid=$username,cn=users,dc=abc,dc=net", "$password");
if ($ldapbind) {
Dmitry Leiko
  • 3,970
  • 3
  • 25
  • 42
  • Amazing that seems to have worked for me. Can you explain what the @ symbol does? or rather an explanation to why it works? – a.smith Nov 25 '19 at 11:03
  • 1
    @a.smith https://stackoverflow.com/questions/1032161/what-is-the-use-of-the-symbol-in-php – Dmitry Leiko Nov 25 '19 at 11:04
  • The '@' suppresses error-messages. But in your case the error is a valid message and should not be suppressed. If the error-message is showing up in your output, that is a completely different topic. That would mean that you have `display_errors` set to `true` which you should **never, ever** do on a production system. For more info on the `@` have a look at https://www.php.net/manual/en/language.operators.errorcontrol.php – heiglandreas Nov 26 '19 at 12:37