1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Nette\Security;
13:
14: use Nette;
15:
16:
17:
18: 19: 20: 21: 22:
23: class SimpleAuthenticator extends Nette\Object implements IAuthenticator
24: {
25:
26: private $userlist;
27:
28:
29: 30: 31:
32: public function __construct(array $userlist)
33: {
34: $this->userlist = $userlist;
35: }
36:
37:
38:
39: 40: 41: 42: 43: 44: 45:
46: public function authenticate(array $credentials)
47: {
48: list($username, $password) = $credentials;
49: foreach ($this->userlist as $name => $pass) {
50: if (strcasecmp($name, $username) === 0) {
51: if ((string) $pass === (string) $password) {
52: return new Identity($name);
53: } else {
54: throw new AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
55: }
56: }
57: }
58: throw new AuthenticationException("User '$username' not found.", self::IDENTITY_NOT_FOUND);
59: }
60:
61: }
62: