publicauth.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. namespace OCA\Files_Sharing\Connector;
  9. class PublicAuth extends \Sabre\DAV\Auth\Backend\AbstractBasic {
  10. /**
  11. * @var \OCP\IConfig
  12. */
  13. private $config;
  14. private $share;
  15. /**
  16. * @param \OCP\IConfig $config
  17. */
  18. public function __construct($config) {
  19. $this->config = $config;
  20. }
  21. /**
  22. * Validates a username and password
  23. *
  24. * This method should return true or false depending on if login
  25. * succeeded.
  26. *
  27. * @param string $username
  28. * @param string $password
  29. *
  30. * @return bool
  31. */
  32. protected function validateUserPass($username, $password) {
  33. $linkItem = \OCP\Share::getShareByToken($username, false);
  34. \OC_User::setIncognitoMode(true);
  35. $this->share = $linkItem;
  36. if (!$linkItem) {
  37. return false;
  38. }
  39. // check if the share is password protected
  40. if (isset($linkItem['share_with'])) {
  41. if ($linkItem['share_type'] == \OCP\Share::SHARE_TYPE_LINK) {
  42. // Check Password
  43. $forcePortable = (CRYPT_BLOWFISH != 1);
  44. $hasher = new \PasswordHash(8, $forcePortable);
  45. if (!$hasher->CheckPassword($password . $this->config->getSystemValue('passwordsalt', ''), $linkItem['share_with'])) {
  46. return false;
  47. } else {
  48. return true;
  49. }
  50. } else {
  51. return false;
  52. }
  53. } else {
  54. return true;
  55. }
  56. }
  57. /**
  58. * @return array
  59. */
  60. public function getShare() {
  61. return $this->share;
  62. }
  63. }