PDO.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. declare(strict_types=1);
  3. namespace Sabre\DAV\Auth\Backend;
  4. /**
  5. * This is an authentication backend that uses a database to manage passwords.
  6. *
  7. * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
  8. * @author Evert Pot (http://evertpot.com/)
  9. * @license http://sabre.io/license/ Modified BSD License
  10. */
  11. class PDO extends AbstractDigest
  12. {
  13. /**
  14. * Reference to PDO connection.
  15. *
  16. * @var PDO
  17. */
  18. protected $pdo;
  19. /**
  20. * PDO table name we'll be using.
  21. *
  22. * @var string
  23. */
  24. public $tableName = 'users';
  25. /**
  26. * Creates the backend object.
  27. *
  28. * If the filename argument is passed in, it will parse out the specified file fist.
  29. */
  30. public function __construct(\PDO $pdo)
  31. {
  32. $this->pdo = $pdo;
  33. }
  34. /**
  35. * Returns the digest hash for a user.
  36. *
  37. * @param string $realm
  38. * @param string $username
  39. *
  40. * @return string|null
  41. */
  42. public function getDigestHash($realm, $username)
  43. {
  44. $stmt = $this->pdo->prepare('SELECT digesta1 FROM '.$this->tableName.' WHERE username = ?');
  45. $stmt->execute([$username]);
  46. return $stmt->fetchColumn() ?: null;
  47. }
  48. }