Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Mail / Protocol / Smtp / Auth / Crammd5.php
blob5b5ca611c7e81cd0d57464a5887ee82362fb3b4a
1 <?php
2 /**
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
8 */
10 namespace Zend\Mail\Protocol\Smtp\Auth;
12 use Zend\Crypt\Hmac;
13 use Zend\Mail\Protocol\Smtp;
15 /**
16 * Performs CRAM-MD5 authentication
18 class Crammd5 extends Smtp
20 /**
21 * @var string
23 protected $username;
26 /**
27 * @var string
29 protected $password;
32 /**
33 * Constructor.
35 * All parameters may be passed as an array to the first argument of the
36 * constructor. If so,
38 * @param string|array $host (Default: 127.0.0.1)
39 * @param null|int $port (Default: null)
40 * @param null|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);
50 } else {
51 $config = $host;
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);
69 /**
70 * Performs CRAM-MD5 authentication with supplied credentials
72 public function auth()
74 // Ensure AUTH has not already been initiated.
75 parent::auth();
77 $this->_send('AUTH CRAM-MD5');
78 $challenge = $this->_expect(334);
79 $challenge = base64_decode($challenge);
80 $digest = $this->_hmacMd5($this->getPassword(), $challenge);
81 $this->_send(base64_encode($this->getUsername() . ' ' . $digest));
82 $this->_expect(235);
83 $this->auth = true;
86 /**
87 * Set value for username
89 * @param string $username
90 * @return Crammd5
92 public function setUsername($username)
94 $this->username = $username;
95 return $this;
98 /**
99 * Get username
101 * @return string
103 public function getUsername()
105 return $this->username;
109 * Set value for password
111 * @param string $password
112 * @return Crammd5
114 public function setPassword($password)
116 $this->password = $password;
117 return $this;
121 * Get password
123 * @return string
125 public function getPassword()
127 return $this->password;
131 * Prepare CRAM-MD5 response to server's ticket
133 * @param string $key Challenge key (usually password)
134 * @param string $data Challenge data
135 * @param int $block Length of blocks (deprecated; unused)
136 * @return string
138 protected function _hmacMd5($key, $data, $block = 64)
140 return Hmac::compute($key, 'md5', $data);