-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathArrayUserPassword.php
More file actions
51 lines (43 loc) · 1.15 KB
/
ArrayUserPassword.php
File metadata and controls
51 lines (43 loc) · 1.15 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
namespace PhpMiddleware\HttpAuthentication\CredentialAdapter;
use PhpMiddleware\HttpAuthentication\CredentialAdapter\Exception\UsernameNotFoundException;
use PhpMiddleware\HttpAuthentication\Util;
final class ArrayUserPassword implements UserPasswordInterface, HashProviderInterface
{
/**
* @var array
*/
protected $users;
/**
* @param array $users
*/
public function __construct(array $users)
{
$this->users = $users;
}
/**
* @param mixed $username
* @param mixed $password
*
* @return bool
*/
public function authenticate($username, $password)
{
return $this->isUserNameExists($username) && $this->users[$username] === $password;
}
private function isUserNameExists($username)
{
return isset($this->users[$username]);
}
public function getHash($username, $realm)
{
if (!$this->isUserNameExists($username)) {
throw new UsernameNotFoundException('Username does not exist');
}
return Util::md5Implode([
$username,
$realm,
$this->users[$username],
]);
}
}