/** * Binds to LDAP with the supplied credentials or anonymously if specified. * * @param string $username The username to bind with. * @param string $password The password to bind with. * @param bool $anonymous Whether this is an anonymous bind attempt. * @throws LdapBindException */ protected function bind($username, $password, $anonymous = false) { if ($anonymous) { $this->isBound = @ldap_bind($this->connection); } else { $this->isBound = @ldap_bind($this->connection, LdapUtilities::encode($username, $this->config->getEncoding()), LdapUtilities::encode($password, $this->config->getEncoding())); } if (!$this->isBound) { throw new LdapBindException(sprintf('Unable to bind to LDAP: %s', $this->getLastError()), $this->getExtendedErrorNumber()); } }