1<?php
2
3/**
4 * Swift Mailer LOGIN Authenticator Mechanism
5 * Please read the LICENSE file
6 * @author Chris Corbyn <chris@w3style.co.uk>
7 * @package Swift_Authenticator
8 * @license GNU Lesser General Public License
9 */
10
11require_once dirname(__FILE__) . "/../ClassLoader.php";
12Swift_ClassLoader::load("Swift_Authenticator");
13
14/**
15 * Swift LOGIN Authenticator
16 * @package Swift_Authenticator
17 * @author Chris Corbyn <chris@w3style.co.uk>
18 */
19class Swift_Authenticator_LOGIN implements Swift_Authenticator
20{
21  /**
22   * Try to authenticate using the username and password
23   * Returns false on failure
24   * @param string The username
25   * @param string The password
26   * @param Swift The instance of Swift this authenticator is used in
27   * @return boolean
28   */
29  public function isAuthenticated($user, $pass, Swift $swift)
30  {
31    try {
32      $swift->command("AUTH LOGIN", 334);
33      $swift->command(base64_encode($user), 334);
34      $swift->command(base64_encode($pass), 235);
35    } catch (Swift_ConnectionException $e) {
36      $swift->reset();
37      return false;
38    }
39    return true;
40  }
41  /**
42   * Return the name of the AUTH extension this is for
43   * @return string
44   */
45  public function getAuthExtensionName()
46  {
47    return "LOGIN";
48  }
49}
50