Namespaces

  • Nette
    • Application
      • Diagnostics
      • Responses
      • Routers
      • UI
    • Caching
      • Storages
    • ComponentModel
    • Config
      • Adapters
      • Extensions
    • Database
      • Diagnostics
      • Drivers
      • Reflection
      • Table
    • DI
      • Diagnostics
    • Diagnostics
    • Forms
      • Controls
      • Rendering
    • Http
    • Iterators
    • Latte
      • Macros
    • Loaders
    • Localization
    • Mail
    • Reflection
    • Security
      • Diagnostics
    • Templating
    • Utils
      • PhpGenerator
  • NetteModule
  • none

Classes

  • Identity
  • Permission
  • SimpleAuthenticator
  • User

Interfaces

  • IAuthenticator
  • IAuthorizator
  • IIdentity
  • IResource
  • IRole
  • IUserStorage

Exceptions

  • AuthenticationException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Other releases
  • Nette homepage
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (https://nette.org)
 5:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 6:  */
 7: 
 8: namespace Nette\Security;
 9: 
10: use Nette;
11: 
12: 
13: /**
14:  * Trivial implementation of IAuthenticator.
15:  *
16:  * @author     David Grudl
17:  */
18: class SimpleAuthenticator extends Nette\Object implements IAuthenticator
19: {
20:     /** @var array */
21:     private $userlist;
22: 
23: 
24:     /**
25:      * @param  array  list of pairs username => password
26:      */
27:     public function __construct(array $userlist)
28:     {
29:         $this->userlist = $userlist;
30:     }
31: 
32: 
33:     /**
34:      * Performs an authentication against e.g. database.
35:      * and returns IIdentity on success or throws AuthenticationException
36:      * @return IIdentity
37:      * @throws AuthenticationException
38:      */
39:     public function authenticate(array $credentials)
40:     {
41:         list($username, $password) = $credentials;
42:         foreach ($this->userlist as $name => $pass) {
43:             if (strcasecmp($name, $username) === 0) {
44:                 if ((string) $pass === (string) $password) {
45:                     return new Identity($name);
46:                 } else {
47:                     throw new AuthenticationException('Invalid password.', self::INVALID_CREDENTIAL);
48:                 }
49:             }
50:         }
51:         throw new AuthenticationException("User '$username' not found.", self::IDENTITY_NOT_FOUND);
52:     }
53: 
54: }
55: 
Nette 2.0 API documentation generated by ApiGen 2.8.0