Dude
Dude

Reputation: 230

LDAP Authentication php doesn't work with certain characters

I'm connecting with the following code to a MS AD-server via php:

<?php
    $login='domain\\username';
    $password='somepaswordwithç';
    $ldap=ldap_connect("someserver.com");
    if ($bind = @ldap_bind($ldap, $login, $password)) {
        echo "ok";
    }
    else{
        echo "error while connecting";
    }
?>

It works with other characters like + / - * " ' but not with ç and possibly some other special characters.

In my original code, I'm getting the values from a post, but the problem is the same when I just put the password in the code above.

Upvotes: 2

Views: 1795

Answers (1)

Dude
Dude

Reputation: 230

It apears I forgot to set the ldap option:

ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);

So the correct code is:

<?php
    $login='domain\\username';
    $password='somepaswordwithç';
    $ldap=ldap_connect("someserver.com");
    ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3);
    if ($bind = @ldap_bind($ldap, $login, $password)) {
        echo "ok";
    }
    else{
        echo "error while connecting";
    }
?>

Upvotes: 3

Related Questions