$oEntry = $oAuth->authenticateHash(array()); $this->fail('Should throw an AuthenticationException, the credentials are missing.'); } catch (AuthenticationException $e) { } if (!defined('MAGIC_STRING')) { try { $oEntry = $oAuth->authenticateHash(array('identifier' => 'Luke Skywalker', 'password' => 'Luke Skywalker')); $this->fail('Should throw an IllegalStateException, the MAGIC_STRING is not defined.'); } catch (IllegalStateException $e) { } } if (!defined('MAGIC_STRING')) { define('MAGIC_STRING', 'This is a magic string used to salt hash.'); } try { $oEntry = $oAuth->authenticate(array('identifier' => 'unexistant', 'password' => 'idem')); $this->fail('Should throw an LDAPException, credentials are incorrect.'); } catch (LDAPException $e) { } try { $oEntry = $oAuth->authenticate(array('identifier' => '', 'password' => '')); $this->fail('Should throw an LDAPException, credentials are incorrect.'); } catch (LDAPException $e) { } try { $oEntry = $oAuth->authenticateHash(array('identifier' => 'unexistant', 'password' => 'idem')); $this->fail('Should throw an LDAPException, credentials are incorrect.'); } catch (LDAPException $e) { } try { $oEntry = $oAuth->authenticateHash(array('identifier' => '', 'password' => ''));
<?php // This could be data sent by a form, for example $aTest = array('identifier' => 'Luke Skywalker', 'password' => 'mypassword42'); // Create the authentication driver $oAuth = new weeAuthLDAP(array('ldap' => $oLDAP, 'base_dn' => 'ou=people, dc=example, dc=com')); try { $oEntry = $oAuth->authenticate($aTest); // Authentication succeeded } catch (AuthenticationException $e) { // Authentication failed }