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