ACC SHELL

Path : /var/lib/named/var/lib/named/proc/self/root/srv/www/vhosts/unisol/app/models/
File Upload :
Current File : //var/lib/named/var/lib/named/proc/self/root/srv/www/vhosts/unisol/app/models/Authenticator.php

<?php

use Nette\Security,
	Nette\Utils\Strings;

class Authenticator extends Nette\Object implements Security\IAuthenticator
{

	private $database;


	public function __construct(Nette\Database\Connection $database)
	{
		$this->database = $database;
	}

	public function authenticate(array $credentials)
	{

   
		list($username, $password) = $credentials;
		$row = $this->database->table('osoby')->where('prezdivka', $username)->fetch();
    
		if (!$row) {
			throw new Security\AuthenticationException('Špatná přezdívka', self::IDENTITY_NOT_FOUND);
		}

		if ($row->heslo !== $this->calculateHash($password, $row->heslo)) {
			throw new Security\AuthenticationException('Špatné heslo', self::INVALID_CREDENTIAL);
		}
       
		$arr = $row->toArray();
		unset($arr['heslo']);
		return new Nette\Security\Identity($row->id_osoby, $row->role, $arr);   
    	}

	public static function calculateHash($password, $salt = NULL)
	{
		if ($password === Strings::upper($password)) { 
			$password = Strings::lower($password);
		}
		return crypt($password, $salt ?: '$2a$07$' . Strings::random(22));
	}

}

ACC SHELL 2018