dummy.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. /**
  3. * ownCloud
  4. *
  5. * @author Frank Karlitschek
  6. * @copyright 2012 Frank Karlitschek frank@owncloud.org
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  10. * License as published by the Free Software Foundation; either
  11. * version 3 of the License, or any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public
  19. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * dummy user backend, does not keep state, only for testing use
  24. */
  25. class OC_User_Dummy extends OC_User_Backend {
  26. private $users=array();
  27. /**
  28. * @brief Create a new user
  29. * @param $uid The username of the user to create
  30. * @param $password The password of the new user
  31. * @returns true/false
  32. *
  33. * Creates a new user. Basic checking of username is done in OC_User
  34. * itself, not in its subclasses.
  35. */
  36. public function createUser($uid, $password) {
  37. if(isset($this->users[$uid])) {
  38. return false;
  39. }else{
  40. $this->users[$uid]=$password;
  41. return true;
  42. }
  43. }
  44. /**
  45. * @brief delete a user
  46. * @param $uid The username of the user to delete
  47. * @returns true/false
  48. *
  49. * Deletes a user
  50. */
  51. public function deleteUser( $uid ) {
  52. if(isset($this->users[$uid])) {
  53. unset($this->users[$uid]);
  54. return true;
  55. }else{
  56. return false;
  57. }
  58. }
  59. /**
  60. * @brief Set password
  61. * @param $uid The username
  62. * @param $password The new password
  63. * @returns true/false
  64. *
  65. * Change the password of a user
  66. */
  67. public function setPassword($uid, $password) {
  68. if(isset($this->users[$uid])) {
  69. $this->users[$uid]=$password;
  70. return true;
  71. }else{
  72. return false;
  73. }
  74. }
  75. /**
  76. * @brief Check if the password is correct
  77. * @param $uid The username
  78. * @param $password The password
  79. * @returns string
  80. *
  81. * Check if the password is correct without logging in the user
  82. * returns the user id or false
  83. */
  84. public function checkPassword($uid, $password) {
  85. if(isset($this->users[$uid])) {
  86. return ($this->users[$uid]==$password);
  87. }else{
  88. return false;
  89. }
  90. }
  91. /**
  92. * @brief Get a list of all users
  93. * @returns array with all uids
  94. *
  95. * Get a list of all users.
  96. */
  97. public function getUsers($search = '', $limit = null, $offset = null) {
  98. return array_keys($this->users);
  99. }
  100. /**
  101. * @brief check if a user exists
  102. * @param string $uid the username
  103. * @return boolean
  104. */
  105. public function userExists($uid) {
  106. return isset($this->users[$uid]);
  107. }
  108. }