PageRenderTime 329ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/php-pear-Auth-1.6.2/Auth-1.6.2/Container.php

#
PHP | 262 lines | 88 code | 36 blank | 138 comment | 9 complexity | 95df5c9be54212acd608698daa8abc86 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4 foldmethod=marker: */
  3. /**
  4. * Auth_Container Base Class
  5. *
  6. * PHP versions 4 and 5
  7. *
  8. * LICENSE: This source file is subject to version 3.01 of the PHP license
  9. * that is available through the world-wide-web at the following URI:
  10. * http://www.php.net/license/3_01.txt. If you did not receive a copy of
  11. * the PHP License and are unable to obtain it through the web, please
  12. * send a note to license@php.net so we can mail you a copy immediately.
  13. *
  14. * @category Authentication
  15. * @package Auth
  16. * @author Martin Jansen <mj@php.net>
  17. * @author Adam Ashley <aashley@php.net>
  18. * @copyright 2001-2006 The PHP Group
  19. * @license http://www.php.net/license/3_01.txt PHP License 3.01
  20. * @version CVS: $Id: Container.php 237449 2007-06-12 03:11:27Z aashley $
  21. * @link http://pear.php.net/package/Auth
  22. */
  23. /**
  24. * Storage class for fetching login data
  25. *
  26. * @category Authentication
  27. * @package Auth
  28. * @author Martin Jansen <mj@php.net>
  29. * @author Adam Ashley <aashley@php.net>
  30. * @copyright 2001-2006 The PHP Group
  31. * @license http://www.php.net/license/3_01.txt PHP License 3.01
  32. * @version Release: 1.6.2 File: $Revision: 237449 $
  33. * @link http://pear.php.net/package/Auth
  34. */
  35. class Auth_Container
  36. {
  37. // {{{ properties
  38. /**
  39. * User that is currently selected from the storage container.
  40. *
  41. * @access public
  42. */
  43. var $activeUser = "";
  44. /**
  45. * The Auth object this container is attached to.
  46. *
  47. * @access public
  48. */
  49. var $_auth_obj = null;
  50. // }}}
  51. // {{{ Auth_Container() [constructor]
  52. /**
  53. * Constructor
  54. *
  55. * Has to be overwritten by each storage class
  56. *
  57. * @access public
  58. */
  59. function Auth_Container()
  60. {
  61. }
  62. // }}}
  63. // {{{ fetchData()
  64. /**
  65. * Fetch data from storage container
  66. *
  67. * Has to be overwritten by each storage class
  68. *
  69. * @access public
  70. */
  71. function fetchData($username, $password, $isChallengeResponse=false)
  72. {
  73. $this->log('Auth_Container::fetchData() called.', AUTH_LOG_DEBUG);
  74. }
  75. // }}}
  76. // {{{ verifyPassword()
  77. /**
  78. * Crypt and verfiy the entered password
  79. *
  80. * @param string Entered password
  81. * @param string Password from the data container (usually this password
  82. * is already encrypted.
  83. * @param string Type of algorithm with which the password from
  84. * the container has been crypted. (md5, crypt etc.)
  85. * Defaults to "md5".
  86. * @return bool True, if the passwords match
  87. */
  88. function verifyPassword($password1, $password2, $cryptType = "md5")
  89. {
  90. $this->log('Auth_Container::verifyPassword() called.', AUTH_LOG_DEBUG);
  91. switch ($cryptType) {
  92. case "crypt" :
  93. return ((string)crypt($password1, $password2) === (string)$password2);
  94. break;
  95. case "none" :
  96. case "" :
  97. return ((string)$password1 === (string)$password2);
  98. break;
  99. case "md5" :
  100. return ((string)md5($password1) === (string)$password2);
  101. break;
  102. default :
  103. if (function_exists($cryptType)) {
  104. return ((string)$cryptType($password1) === (string)$password2);
  105. } elseif (method_exists($this,$cryptType)) {
  106. return ((string)$this->$cryptType($password1) === (string)$password2);
  107. } else {
  108. return false;
  109. }
  110. break;
  111. }
  112. }
  113. // }}}
  114. // {{{ supportsChallengeResponse()
  115. /**
  116. * Returns true if the container supports Challenge Response
  117. * password authentication
  118. */
  119. function supportsChallengeResponse()
  120. {
  121. return(false);
  122. }
  123. // }}}
  124. // {{{ getCryptType()
  125. /**
  126. * Returns the crypt current crypt type of the container
  127. *
  128. * @return string
  129. */
  130. function getCryptType()
  131. {
  132. return('');
  133. }
  134. // }}}
  135. // {{{ listUsers()
  136. /**
  137. * List all users that are available from the storage container
  138. */
  139. function listUsers()
  140. {
  141. $this->log('Auth_Container::listUsers() called.', AUTH_LOG_DEBUG);
  142. return AUTH_METHOD_NOT_SUPPORTED;
  143. }
  144. // }}}
  145. // {{{ getUser()
  146. /**
  147. * Returns a user assoc array
  148. *
  149. * Containers which want should overide this
  150. *
  151. * @param string The username
  152. */
  153. function getUser($username)
  154. {
  155. $this->log('Auth_Container::getUser() called.', AUTH_LOG_DEBUG);
  156. $users = $this->listUsers();
  157. if ($users === AUTH_METHOD_NOT_SUPPORTED) {
  158. return AUTH_METHOD_NOT_SUPPORTED;
  159. }
  160. for ($i=0; $c = count($users), $i<$c; $i++) {
  161. if ($users[$i]['username'] == $username) {
  162. return $users[$i];
  163. }
  164. }
  165. return false;
  166. }
  167. // }}}
  168. // {{{ addUser()
  169. /**
  170. * Add a new user to the storage container
  171. *
  172. * @param string Username
  173. * @param string Password
  174. * @param array Additional information
  175. *
  176. * @return boolean
  177. */
  178. function addUser($username, $password, $additional=null)
  179. {
  180. $this->log('Auth_Container::addUser() called.', AUTH_LOG_DEBUG);
  181. return AUTH_METHOD_NOT_SUPPORTED;
  182. }
  183. // }}}
  184. // {{{ removeUser()
  185. /**
  186. * Remove user from the storage container
  187. *
  188. * @param string Username
  189. */
  190. function removeUser($username)
  191. {
  192. $this->log('Auth_Container::removeUser() called.', AUTH_LOG_DEBUG);
  193. return AUTH_METHOD_NOT_SUPPORTED;
  194. }
  195. // }}}
  196. // {{{ changePassword()
  197. /**
  198. * Change password for user in the storage container
  199. *
  200. * @param string Username
  201. * @param string The new password
  202. */
  203. function changePassword($username, $password)
  204. {
  205. $this->log('Auth_Container::changePassword() called.', AUTH_LOG_DEBUG);
  206. return AUTH_METHOD_NOT_SUPPORTED;
  207. }
  208. // }}}
  209. // {{{ log()
  210. /**
  211. * Log a message to the Auth log
  212. *
  213. * @param string The message
  214. * @param int
  215. * @return boolean
  216. */
  217. function log($message, $level = AUTH_LOG_DEBUG) {
  218. if (is_null($this->_auth_obj)) {
  219. return false;
  220. } else {
  221. return $this->_auth_obj->log($message, $level);
  222. }
  223. }
  224. // }}}
  225. }
  226. ?>