3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
10 namespace Zend\Mail\Protocol\Smtp\Auth
;
12 use Zend\Mail\Protocol\Smtp
;
15 * Performs PLAIN authentication
17 class Plain
extends Smtp
38 * @param string $host (Default: 127.0.0.1)
39 * @param int $port (Default: null)
40 * @param array $config Auth-specific parameters
42 public function __construct($host = '127.0.0.1', $port = null, $config = null)
44 // Did we receive a configuration array?
45 $origConfig = $config;
46 if (is_array($host)) {
47 // Merge config array with principal array, if provided
48 if (is_array($config)) {
49 $config = array_replace_recursive($host, $config);
55 if (is_array($config)) {
56 if (isset($config['username'])) {
57 $this->setUsername($config['username']);
59 if (isset($config['password'])) {
60 $this->setPassword($config['password']);
64 // Call parent with original arguments
65 parent
::__construct($host, $port, $origConfig);
70 * Perform PLAIN authentication with supplied credentials
73 public function auth()
75 // Ensure AUTH has not already been initiated.
78 $this->_send('AUTH PLAIN');
80 $this->_send(base64_encode("\0" . $this->getUsername() . "\0" . $this->getPassword()));
86 * Set value for username
88 * @param string $username
91 public function setUsername($username)
93 $this->username
= $username;
102 public function getUsername()
104 return $this->username
;
108 * Set value for password
110 * @param string $password
113 public function setPassword($password)
115 $this->password
= $password;
124 public function getPassword()
126 return $this->password
;