/**
  * 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)
 {
     try {
         $swift->command("AUTH LOGIN", 334);
         $swift->command(base64_encode($user), 334);
         $swift->command(base64_encode($pass), 235);
     } catch (Swift_ConnectionException $e) {
         $swift->reset();
         return false;
     }
     return true;
 }
 /**
  * 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)
 {
     try {
         $encoded_challenge = substr($swift->command("AUTH CRAM-MD5", 334)->getString(), 4);
         $challenge = base64_decode($encoded_challenge);
         $response = base64_encode($user . " " . self::generateCRAMMD5Hash($pass, $challenge));
         $swift->command($response, 235);
     } catch (Swift_ConnectionException $e) {
         $swift->reset();
         return false;
     }
     return true;
 }
Example #3
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)
 {
     try {
         //The authorization string uses ascii null as a separator (See RFC 2554)
         $credentials = base64_encode($user . chr(0) . $user . chr(0) . $pass);
         $swift->command("AUTH PLAIN " . $credentials, 235);
     } catch (Swift_ConnectionException $e) {
         $swift->reset();
         return false;
     }
     return true;
 }
 /**
  * Send a command to Swift and get a response
  * @param string The command to send (leave of CRLF)
  * @return string
  */
 public function command($command)
 {
     if (substr($command, -2) == "\r\n") {
         $command = substr($command, 0, -2);
     }
     try {
         $rs = $this->swift->command($command);
         return $rs->getString();
     } catch (Swift_ConnectionException $e) {
         $this->setError("Command failed:<br />" . $e->getMessage());
         return false;
     }
 }
Example #5
0
 /**
  * Send a command to Swift and get a response
  * @param string The command to send (leave of CRLF)
  * @return string
  */
 function command($command)
 {
     if (substr($command, -2) == "\r\n") {
         $command = substr($command, 0, -2);
     }
     Swift_Errors::expect($e, "Swift_ConnectionException");
     $rs =& $this->swift->command($command);
     if ($e) {
         $this->setError("Command failed:<br />" . $e->getMessage());
         return false;
     }
     Swift_Errors::clear("Swift_ConnectionException");
     return $rs->getString();
 }
 public function testBytesPerMinuteThrottling()
 {
     $conn = new FullMockConnection();
     for ($i = 0; $i < 10; $i++) {
         $conn->setReturnValueAt($i, "read", "250 xx");
     }
     $swift = new Swift($conn, null, Swift::NO_START);
     set_time_limit(90);
     //60 secs expected + standard 30 secs
     $plugin = new Swift_Plugin_Throttler();
     //Outgoing bytes
     $plugin->setBytesPerMinute(60);
     $swift->attachPlugin($plugin, "throttler");
     $start = time();
     for ($i = 0; $i < 10; $i++) {
         //4 + 2 = 6 bytes each (and 6 x 10 = 60)
         $swift->command("1234");
     }
     $end = time();
     $duration = $end - $start;
     $this->assertTrue($duration >= 60);
     $this->dump("Sending 60 bytes at 60 bytes per minute took " . $duration . " secs");
     //
     $conn = new FullMockConnection();
     for ($i = 0; $i < 10; $i++) {
         $conn->setReturnValueAt($i, "read", "250 xx");
     }
     $swift = new Swift($conn, null, Swift::NO_START);
     set_time_limit(50);
     //20 secs expected + standard 30 secs
     $plugin = new Swift_Plugin_Throttler();
     //Outgoing bytes
     $plugin->setBytesPerMinute(180);
     $swift->attachPlugin($plugin, "throttler");
     $start = time();
     for ($i = 0; $i < 10; $i++) {
         //4 + 2 = 6 bytes each (and 6 x 10 = 60)
         $swift->command("ab c");
     }
     $end = time();
     $duration = $end - $start;
     $this->assertTrue($duration >= 20);
     $this->dump("Sending 60 bytes at 180 bytes per minute took " . $duration . " secs");
 }
 /**
  * The counters should be settable through setBytesIn() and setBytesOut().
  */
 public function testBytesCanBeReset()
 {
     $conn = new FullMockConnection();
     //7 chars + 2 for EOL
     $conn->setReturnValueAt(0, "read", "250 foo");
     //15 chars + 2 for EOL
     $conn->setReturnValueAt(1, "read", "221 bye for now");
     $swift = new Swift($conn, null, Swift::NO_START);
     $plugin = new Swift_Plugin_BandwidthMonitor();
     $swift->attachPlugin($plugin, "bwmon");
     //20 chars + 2 for EOL
     $swift->command("abcdefghijklm 123456");
     $this->assertEqual(22, $plugin->getBytesOut());
     $this->assertEqual(9, $plugin->getBytesIn());
     $plugin->setBytesOut(0);
     $this->assertEqual(0, $plugin->getBytesOut());
     //3 chars + 2 for EOL
     $swift->command("bar");
     $this->assertEqual(5, $plugin->getBytesOut());
     $this->assertEqual(26, $plugin->getBytesIn());
     $plugin->setBytesIn(0);
     $this->assertEqual(0, $plugin->getBytesIn());
 }