src/Adapter/Basic/Ldap.php
public function plainAuth(string $username, string $password): bool
    {
        $resource = $this->ldap->getResource();

        $esc_username = ldap_escape($username);
        $filter = htmlspecialchars_decode(sprintf($this->account_filter, $esc_username));
        $result = ldap_search($resource, $this->ldap->getBase(), $filter, ['dn', $this->identity_attribute]);
        $entries = ldap_get_entries($resource, $result);

        if (0 === $entries['count']) {
            $this->logger->warning("user not found with ldap filter [{$filter}]", [
                'category' => get_class($this),
            ]);

            return false;
        }
        if ($entries['count'] > 1) {
            $this->logger->warning("more than one user found with ldap filter [{$filter}]", [
                'category' => get_class($this),
            ]);

            return false;
        }

        $dn = $entries[0]['dn'];
        $this->logger->info("found ldap user [{$dn}] with filter [{$filter}]", [
            'category' => get_class($this),
        ]);

        $result = ldap_bind($resource, $dn, $password);
        $this->logger->info("bind ldap user [{$dn}]", [
            'category' => get_class($this),
            'result' => $result,
        ]);

        if (false === $result) {
            return false;
        }

        if (!isset($entries[0][$this->identity_attribute])) {
            throw new Exception\IdentityAttributeNotFound('identity attribute not found');
        }

        $this->identifier = $entries[0][$this->identity_attribute][0];
        $this->ldap_dn = $dn;

        return true;
    }
public function plainAuth(string $username, string $password): bool
    {
        $resource = $this->ldap->getResource();

        $esc_username = ldap_escape($username);
        $filter = htmlspecialchars_decode(sprintf($this->account_filter, $esc_username));
        $result = ldap_search($resource, $this->ldap->getBase(), $filter, ['dn', $this->identity_attribute]);
        $entries = ldap_get_entries($resource, $result);

        if (0 === $entries['count']) {
            $this->logger->warning("user not found with ldap filter [{$filter}]", [
                'category' => get_class($this),
            ]);

            return false;
        }
        if ($entries['count'] > 1) {
            $this->logger->warning("more than one user found with ldap filter [{$filter}]", [
                'category' => get_class($this),
            ]);

            return false;
        }

        $dn = $entries[0]['dn'];
        $this->logger->info("found ldap user [{$dn}] with filter [{$filter}]", [
            'category' => get_class($this),
        ]);

        $result = ldap_bind($resource, $dn, $password);
        $this->logger->info("bind ldap user [{$dn}]", [
            'category' => get_class($this),
            'result' => $result,
        ]);

        if (false === $result) {
            return false;
        }

        if (!isset($entries[0][$this->identity_attribute])) {
            throw new Exception\IdentityAttributeNotFound('identity attribute not found');
        }

        $this->identifier = $entries[0][$this->identity_attribute][0];
        $this->ldap_dn = $dn;

        return true;
    }
public function plainAuth ( string $ username , string $ password ) : bool { $ resource = $ this -> ldap -> getResource ( ) ; $ esc_username = ldap_escape ( $ username ) ; $ filter = htmlspecialchars_decode ( sprintf ( $ this -> account_filter , $ esc_username ) ) ; $ result = ldap_search ( $ resource , $ this -> ldap -> getBase ( ) , $ filter , [ 'dn' , $ this -> identity_attribute ] ) ; $ entries = ldap_get_entries ( $ resource , $ result ) ; if ( 0 === $ entries [ 'count' ] ) { $ this -> logger -> warning ( "user not found with ldap filter [{$filter}]" , [ 'category' => get_class ( $ this ) , ] ) ; return false ; } if ( $ entries [ 'count' ] > 1 ) { $ this -> logger -> warning ( "more than one user found with ldap filter [{$filter}]" , [ 'category' => get_class ( $ this ) , ] ) ; return false ; } $ dn = $ entries [ 0 ] [ 'dn' ] ; $ this -> logger -> info ( "found ldap user [{$dn}] with filter [{$filter}]" , [ 'category' => get_class ( $ this ) , ] ) ; $ result = ldap_bind ( $ resource , $ dn , $ password ) ; $ this -> logger -> info ( "bind ldap user [{$dn}]" , [ 'category' => get_class ( $ this ) , 'result' => $ result , ] ) ; if ( false === $ result ) { return false ; } if ( ! isset ( $ entries [ 0 ] [ $ this -> identity_attribute ] ) ) { throw new Exception \ IdentityAttributeNotFound ( 'identity attribute not found' ) ; } $ this -> identifier = $ entries [ 0 ] [ $ this -> identity_attribute ] [ 0 ] ; $ this -> ldap_dn = $ dn ; return true ; }
LDAP Auth.

@param string $username
@param string $password

@return bool
LDAP Auth .