/** * * Binds to the LDAP server with username and password. * * @param resource $conn The LDAP connection. * * @param string $username The input username. * * @param string $password The input password. * * @throws Exception\BindFailed when the username/password fails. * */ protected function bind($conn, $username, $password) { $username = $this->escape($username); $bind_rdn = sprintf($this->dnformat, $username); $bound = $this->phpfunc->ldap_bind($conn, $bind_rdn, $password); if (!$bound) { $error = $this->phpfunc->ldap_errno($conn) . ': ' . $this->phpfunc->ldap_error($conn); $this->phpfunc->ldap_close($conn); throw new Exception\BindFailed($error); } $this->phpfunc->ldap_unbind($conn); $this->phpfunc->ldap_close($conn); }