1<?php
2
3/**
4 * Swift Mailer PLAIN 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 PLAIN Authenticator
16 * This form of authentication is unbelievably insecure since everything is done plain-text
17 * @package Swift_Authenticator
18 * @author Chris Corbyn <chris@w3style.co.uk>
19 */
20class Swift_Authenticator_PLAIN implements Swift_Authenticator
21{
22  /**
23   * Try to authenticate using the username and password
24   * Returns false on failure
25   * @param string The username
26   * @param string The password
27   * @param Swift The instance of Swift this authenticator is used in
28   * @return boolean
29   */
30  public function isAuthenticated($user, $pass, Swift $swift)
31  {
32    try {
33      //The authorization string uses ascii null as a separator (See RFC 2554)
34      $credentials = base64_encode($user . chr(0) . $user . chr(0) . $pass);
35      $swift->command("AUTH PLAIN " . $credentials, 235);
36    } catch (Swift_ConnectionException $e) {
37      $swift->reset();
38      return false;
39    }
40    return true;
41  }
42  /**
43   * Return the name of the AUTH extension this is for
44   * @return string
45   */
46  public function getAuthExtensionName()
47  {
48    return "PLAIN";
49  }
50}
51