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: $username = $credentials[self::USERNAME];
49: foreach ($this->userlist as $name => $pass) {
50: if (strcasecmp($name, $credentials[self::USERNAME]) === 0) {
51: if (strcasecmp($pass, $credentials[self::PASSWORD]) === 0) {
52:
53: return new Identity($name);
54: }
55:
56: throw new AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
57: }
58: }
59:
60: throw new AuthenticationException("User '$username' not found.", self::IDENTITY_NOT_FOUND);
61: }
62:
63: }
64: