aboutsummaryrefslogtreecommitdiff
path: root/Psso/AuthProvider/ConfigFile.php
blob: e9b45ce162c513b841887ceb082336e543d66162 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace Psso\AuthProvider;
use Psso\AuthProvider;
use Psso\AuthInterface\{Groups, Password, UserExists, UserExtra};

class ConfigFile extends AuthProvider
implements Password, UserExists, UserExtra, Groups {
    public function validatePassword(
        string $username,
        #[\SensitiveParameter] string $password
    ): bool {
        $hash = $this->config['users'][$username]['password-hash'] ?? null;
        if (!isset($hash)) {
            return false;
        }
        return password_verify($password, $hash);
    }

    public function userExists(string $username): bool {
        return isset($this->config['users'][$username]);
    }

    public function userGroups(string $username): array {
        $gstr = $this->config['users'][$username]['groups'] ?? '';
        $groups = [];
        for ($ng = strtok($gstr, ' '); $ng !== false; $ng = strtok(' '))
            $groups[] = $ng;
        return $groups;
    }

    public function userDisplayName(string $username): ?string {
        return $this->config['users'][$username]['name'] ?? null;
    }

    public function userEmailAddress(string $username): ?string {
        return $this->config['users'][$username]['email'] ?? null;
    }
}