1<?php
2
3namespace Sabre\DAV\Auth\Backend;
4
5/**
6 * Extremely simply HTTP Basic auth backend.
7 *
8 * This backend basically works by calling a callback, which receives a
9 * username and password.
10 * The callback must return true or false depending on if authentication was
11 * correct.
12 *
13 * @copyright Copyright (C) 2007-2015 fruux GmbH (https://fruux.com/).
14 * @author Evert Pot (http://evertpot.com/)
15 * @license http://sabre.io/license/ Modified BSD License
16 */
17class BasicCallBack extends AbstractBasic {
18
19    /**
20     * Callback
21     *
22     * @var callable
23     */
24    protected $callBack;
25
26    /**
27     * Creates the backend.
28     *
29     * A callback must be provided to handle checking the username and
30     * password.
31     *
32     * @param callable $callBack
33     * @return void
34     */
35    function __construct(callable $callBack) {
36
37        $this->callBack = $callBack;
38
39    }
40
41    /**
42     * Validates a username and password
43     *
44     * This method should return true or false depending on if login
45     * succeeded.
46     *
47     * @param string $username
48     * @param string $password
49     * @return bool
50     */
51    protected function validateUserPass($username, $password) {
52
53        $cb = $this->callBack;
54        return $cb($username, $password);
55
56    }
57
58}
59