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
  • PHP

Classes

  • Identity
  • Permission
  • SimpleAuthenticator
  • User

Interfaces

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

Exceptions

  • AuthenticationException
  • Overview
  • Namespace
  • Class
  • Tree
 1: <?php
 2: 
 3: /**
 4:  * This file is part of the Nette Framework (http://nette.org)
 5:  *
 6:  * Copyright (c) 2004 David Grudl (http://davidgrudl.com)
 7:  *
 8:  * For the full copyright and license information, please view
 9:  * the file license.txt that was distributed with this source code.
10:  */
11: 
12: namespace Nette\Security;
13: 
14: use Nette;
15: 
16: 
17: 
18: /**
19:  * Trivial implementation of IAuthenticator.
20:  *
21:  * @author     David Grudl
22:  */
23: class SimpleAuthenticator extends Nette\Object implements IAuthenticator
24: {
25:     /** @var array */
26:     private $userlist;
27: 
28: 
29:     /**
30:      * @param  array  list of pairs username => password
31:      */
32:     public function __construct(array $userlist)
33:     {
34:         $this->userlist = $userlist;
35:     }
36: 
37: 
38: 
39:     /**
40:      * Performs an authentication against e.g. database.
41:      * and returns IIdentity on success or throws AuthenticationException
42:      * @param  array
43:      * @return IIdentity
44:      * @throws AuthenticationException
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: 
Nette Framework 2.0.0 API API documentation generated by ApiGen 2.7.0