%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /data/www_bck/varak.net_bck/mpr.varak.net/app/model/
Upload File :
Create Path :
Current File : //data/www_bck/varak.net_bck/mpr.varak.net/app/model/Authenticator.php

<?php

use Nette\Security as NS;


/**
 * Users authenticator.
 */
class Authenticator extends Base implements NS\IAuthenticator
{

    /**
     * Performs an authentication
     * @param  array
     * @return Nette\Security\Identity
     * @throws Nette\Security\AuthenticationException
     */
    public function authenticate(array $credentials)
    {
        list($username, $password) = $credentials;
        $res = $this->db->query("select [id], [password], [role], [name] from [users] where [username]=%s", $username);
        $auth = false;
        if($res->count() > 0)
        {
            $usr = $res->fetch();
            if($usr->password == $this->calculateHash($username, $password))
            {
                $auth = true;
            }
        }

        if(!$auth)
        {
            throw new NS\AuthenticationException("Invalid username/password combination", self::INVALID_CREDENTIAL);
        }

        return new NS\Identity($usr->id, $usr->role, array('name' => $usr->name));
    }



    /**
     * Computes salted password hash.
     * @param $username string Username
     * @param $password string Password
     * @return string
     */
    private function calculateHash($username, $password)
    {
        return sha1("$username:$password");
    }
}

Zerion Mini Shell 1.0