3 class Sabre_DAV_Auth_Backend_Std extends Sabre_DAV_Auth_Backend_AbstractBasic {
5 public function __construct() {
10 * @var Sabre_DAV_Auth_Backend_Std|null
12 private static $intstance = null;
16 * @return Sabre_DAV_Auth_Backend_Std
18 public static function &getInstance() {
19 if (is_null(self::$intstance)) {
20 self::$intstance = new Sabre_DAV_Auth_Backend_Std();
22 return self::$intstance;
29 public function getUsers() {
30 return array($this->currentUser);
36 public function getCurrentUser() {
37 return $this->currentUser;
41 * Authenticates the user based on the current request.
43 * If authentication is successful, true must be returned.
44 * If authentication fails, an exception must be thrown.
46 * @param Sabre_DAV_Server $server
47 * @param string $realm
48 * @throws Sabre_DAV_Exception_NotAuthenticated
51 public function authenticate(Sabre_DAV_Server $server, $realm) {
54 if (isset($a->user["uid"])) {
55 $this->currentUser = strtolower($a->user["nickname"]);
59 $auth = new Sabre_HTTP_BasicAuth();
60 $auth->setHTTPRequest($server->httpRequest);
61 $auth->setHTTPResponse($server->httpResponse);
62 $auth->setRealm($realm);
63 $userpass = $auth->getUserPass();
65 $auth->requireLogin();
66 throw new Sabre_DAV_Exception_NotAuthenticated('No basic authentication headers were found');
69 // Authenticates the user
70 if (!$this->validateUserPass($userpass[0],$userpass[1])) {
71 $auth->requireLogin();
72 throw new Sabre_DAV_Exception_NotAuthenticated('Username or password does not match');
74 $this->currentUser = strtolower($userpass[0]);
80 * @param string $username
81 * @param string $password
84 protected function validateUserPass($username, $password) {
85 $encrypted = hash('whirlpool',trim($password));
86 $r = q("SELECT COUNT(*) anz FROM `user` WHERE `nickname` = '%s' AND `password` = '%s' AND `blocked` = 0 AND `account_expired` = 0 AND `verified` = 1 LIMIT 1",
87 dbesc(trim($username)),
90 return ($r[0]["anz"] == 1);