src/Authentication/Handlers/HandlerLDAP.php
public function connectByDN($dn, $password="") {
		// make sure the ldap extension has been loaded
		if(!extension_loaded('ldap')) {
			throw new LdapExtensionNotLoadedException();
		}

		$params = array(
		    'hostname'  => $this->host,
		    'base_dn' => $this->basedn,
		    'options' => [
		    	ConnectionInterface::OPT_PROTOCOL_VERSION => $this->version,
		    ],
		);

		// if there is an overlay, use that as the base DN instead
		if(!empty($this->overlay_dn)) {
			$params['base_dn'] = $this->overlay_dn;
		}

		$this->ldap = new Manager($params, new Driver());

		// connect to the server and bind with the credentials
		try
		{
			$this->ldap->connect();

			// if we do not have a password specified, use the admin DN and
			// password for the connection operation
			if(empty($password)) {
				if($this->allowNoPass) {
					// yes so use the constructor-provided DN and password
					$dn = $this->dn;
					if(!empty($this->overlay_dn)) {
						$dn .= "," . $this->overlay_dn;
					}
					$password = $this->password;
				}
			}

			$this->bind($dn, $password);

			// if it hits this return then the connection was successful and
			// the binding was also successful
			return true;
		}
		catch(BindException $be)
		{
			// could not bind with the provided credentials
			return false;
		}
		catch(Exception $e)
		{
			throw $e;
		}

		// something else went wrong
		return false;
	}
public function connectByDN($dn, $password="") {
		// make sure the ldap extension has been loaded
		if(!extension_loaded('ldap')) {
			throw new LdapExtensionNotLoadedException();
		}

		$params = array(
		    'hostname'  => $this->host,
		    'base_dn' => $this->basedn,
		    'options' => [
		    	ConnectionInterface::OPT_PROTOCOL_VERSION => $this->version,
		    ],
		);

		// if there is an overlay, use that as the base DN instead
		if(!empty($this->overlay_dn)) {
			$params['base_dn'] = $this->overlay_dn;
		}

		$this->ldap = new Manager($params, new Driver());

		// connect to the server and bind with the credentials
		try
		{
			$this->ldap->connect();

			// if we do not have a password specified, use the admin DN and
			// password for the connection operation
			if(empty($password)) {
				if($this->allowNoPass) {
					// yes so use the constructor-provided DN and password
					$dn = $this->dn;
					if(!empty($this->overlay_dn)) {
						$dn .= "," . $this->overlay_dn;
					}
					$password = $this->password;
				}
			}

			$this->bind($dn, $password);

			// if it hits this return then the connection was successful and
			// the binding was also successful
			return true;
		}
		catch(BindException $be)
		{
			// could not bind with the provided credentials
			return false;
		}
		catch(Exception $e)
		{
			throw $e;
		}

		// something else went wrong
		return false;
	}
public function connectByDN ( $ dn , $ password = "" ) { // make sure the ldap extension has been loaded if ( ! extension_loaded ( 'ldap' ) ) { throw new LdapExtensionNotLoadedException ( ) ; } $ params = array ( 'hostname' => $ this -> host , 'base_dn' => $ this -> basedn , 'options' => [ ConnectionInterface :: OPT_PROTOCOL_VERSION => $ this -> version , ] , ) ; // if there is an overlay, use that as the base DN instead if ( ! empty ( $ this -> overlay_dn ) ) { $ params [ 'base_dn' ] = $ this -> overlay_dn ; } $ this -> ldap = new Manager ( $ params , new Driver ( ) ) ; // connect to the server and bind with the credentials try { $ this -> ldap -> connect ( ) ; // if we do not have a password specified, use the admin DN and // password for the connection operation if ( empty ( $ password ) ) { if ( $ this -> allowNoPass ) { // yes so use the constructor-provided DN and password $ dn = $ this -> dn ; if ( ! empty ( $ this -> overlay_dn ) ) { $ dn .= "," . $ this -> overlay_dn ; } $ password = $ this -> password ; } } $ this -> bind ( $ dn , $ password ) ; // if it hits this return then the connection was successful and // the binding was also successful return true ; } catch ( BindException $ be ) { // could not bind with the provided credentials return false ; } catch ( Exception $ e ) { throw $ e ; } // something else went wrong return false ; }
Connects and binds to the LDAP server based on the provided DN and an
optional password. Returns whether the connection and binding were
successful.

@param string $dn The bind DN to use
@param string $password An optional password to use

@throws LdapExtensionNotLoadedException If the LDAP extension has not
been installed and loaded
@throws Exception If the LDAP connection fails
@return boolean
Connects and binds to the LDAP server based on the provided DN and an optional password . Returns whether the connection and binding were successful .