Guest User

www\AclProj\libs\AclProj\Authenticator.php

a guest
Mar 11th, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.12 KB | None | 0 0
  1. <?php
  2.  
  3. namespace AclProj\Security;
  4.  
  5. use Nette;
  6. use Nette\Security\Identity;
  7. use Nette\Security\AuthenticationException;
  8.  
  9. class Authenticator extends Nette\Object implements Nette\Security\IAuthenticator
  10. {
  11.     /** @var Nette\Database\Connection */
  12.     private $database;
  13.  
  14.  
  15.     /**
  16.      * @param Nette\Database\Connection
  17.      */
  18.     public function __construct(Nette\Database\Connection $database)
  19.     {
  20.         $this->database = $database;
  21.     }
  22.  
  23.  
  24.     /**
  25.      * Performas an authentication
  26.      * @param array
  27.      * @return Nette\Security\Identity
  28.      */
  29.     public function authenticate(array $credentials)
  30.     {
  31.         list($login, $password) = $credentials;
  32.         $row = $this->database->table('user')->where('login', $login)->fetch();
  33.  
  34.         if (!$row) {
  35.             throw new AuthenticationException('The login is incorrect.', self::IDENTITY_NOT_FOUND);
  36.         }
  37.  
  38.         if ($row->password !== sha1($password)) {
  39.             throw new AuthenticationException('Wrong password', self::INVALID_CREDENTIAL);
  40.         }
  41.  
  42.         unset($row->password);
  43.         return new Identity($row->id, $row->role, $row->toArray());
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment