Example #1
0
 /**
  * Try to authenticate using the username and password
  * Returns false on failure
  * @param string The username
  * @param string The password
  * @param Swift The instance of Swift this authenticator is used in
  * @return boolean
  */
 public function isAuthenticated($user, $pass, Swift $swift)
 {
   $log = Swift_LogContainer::getLog();
   if ($log->hasLevel(Swift_Log::LOG_EVERYTHING))
   {
     $log->add("Trying POP3 Before SMTP authentication.  Disconnecting from SMTP first.");
   }
   $swift->disconnect();
   try {
     $this->connection->start();
     $this->connection->assertOk($this->connection->read());
     $this->connection->write("USER " . $user);
     $this->connection->assertOk($this->connection->read());
     $this->connection->write("PASS " . $pass);
     $this->connection->assertOk($this->connection->read());
     $this->connection->write("QUIT");
     $this->connection->assertOk($this->connection->read());
     $this->connection->stop();
   } catch (Swift_ConnectionException $e) {
     if ($log->hasLevel(Swift_Log::LOG_ERRORS))
     {
       $log->add($e->getMessage(),Swift_Log::ERROR);
       $log->add("POP3 authentication failed.");
     }
     return false;
   }
   $options = $swift->getOptions();
   $swift->setOptions($options | Swift::NO_POST_CONNECT);
   $swift->connect();
   $swift->setOptions($options);
   return true;
 }