1: <?php
2: /**
3: * IMSP authentication class for plaintext LOGIN authentication.
4: *
5: * Required parameters:<pre>
6: * 'username' Username to logon to IMSP server as.
7: * 'password' Password for current user.
8: * 'server' The hostname of the IMSP server.
9: * 'port' The port of the IMSP server.</pre>
10: *
11: * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
12: *
13: * See the enclosed file COPYING for license information (LGPL). If you
14: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
15: *
16: * @author Michael J Rubinsky <mrubinsk@horde.org>
17: * @package Horde_Imsp
18: */
19: class Horde_Imsp_Auth_Plaintext extends Horde_Imsp_Auth_Base
20: {
21: /**
22: * Private authentication function. Provides actual
23: * authentication code.
24: *
25: * @return boolean
26: */
27: protected function _authenticate()
28: {
29: $userId = $this->_params['username'];
30: $credentials = $this->_params['password'];
31:
32: /* Start the command. */
33: $this->_imsp->send('LOGIN ', true, false);
34:
35: /* Username as a {}? */
36: if (preg_match(Horde_Imsp::MUST_USE_LITERAL, $userId)) {
37: $biUser = sprintf('{%d}', strlen($userId));
38: $result = $this->_imsp->send($biUser, false, true, true);
39: }
40: $this->_imsp->send($userId . ' ', false, false);
41:
42: /* Pass as {}? */
43: if (preg_match(Horde_Imsp::MUST_USE_LITERAL, $credentials)) {
44: $biPass = sprintf('{%d}', strlen($credentials));
45: $this->_imsp->send($biPass, false, true, true);
46: }
47: $this->_imsp->send($credentials, false, true);
48: $server_response = $this->_imsp->receive();
49: if ($server_response != 'OK') {
50: return false;
51: }
52:
53: return true;
54: }
55:
56: /**
57: * Force a logout command to the imsp stream.
58: *
59: */
60: public function logout()
61: {
62: $this->_imsp->logout();
63: }
64:
65: /**
66: * Return the driver type
67: *
68: * @return string the type of this IMSP_Auth driver
69: */
70: public function getDriverType()
71: {
72: return 'plaintext';
73: }
74:
75: }
76: