public function createToken($user, $ttl = 3600)
    {
        $expires = time() + (int) $ttl;

        $hash = $this->getEncoder()->generateTokenValue(
            get_class($user),
            $user->getUsername(),
            $user->getPassword(),
            $expires
        );

        $token = new Token();
        $token->setHash($hash);
        $token->setExpiresAt(new \DateTime('@' . $expires));

        $this->updateToken($token);

        return $token;
    }