public function attempt($username, $password, $bindAsUser = false)
{
$this->validateCredentials($username, $password);
try {
$this->bind($username, $password);
} catch (BindException $e) {
// We'll catch the BindException here to return false
// to allow developers to use a simple if / else
// using the authenticate method.
return false;
}
// If we're not allowed to bind as the user,
// we'll rebind as administrator.
if ($bindAsUser === false) {
// We won't catch any BindException here so
// developers can catch rebind failures.
$this->bindAsAdministrator();
}
// No bind exceptions, authentication passed.
return true;
}