public static function encode($username, $password, $data = [])
    {
        if (!isset($data['nonce'])) {
            $response = base64_encode("{$username}:{$password}");
            return compact('username', 'response');
        }
        $defaults = [
            'realm' => 'app', 'method' => 'GET', 'uri' => '/', 'qop' => null,
            'cnonce' => md5(time()), 'nc' => static::$nc
        ];
        $data = array_filter($data) + $defaults;
        $part1 = md5("{$username}:{$data['realm']}:{$password}");
        $part2 = "{$data['nonce']}:{$data['nc']}:{$data['cnonce']}:{$data['qop']}";
        $part3 = md5($data['method'] . ':' . $data['uri']);
        $response = md5("{$part1}:{$part2}:{$part3}");
        return compact('username', 'response') + $data;
    }