Access a username/password protected url through C++

I'm an individual developer (not a professional developer. I'm a graphic designer who likes to code ) and I mainly code plugins for Cinema 4D (I don't know if anyone knows this application).

I used to code in COFFEE (a javascript like language, only for Cinema 4D) and python.
But, recently, I started coding in C++.

I start my development on a Mac, using Xcode. But then, to generate Windows versions of my plugins, I take my source code to Visual Studio, perform the necessary adjustments, and create Win32 and Win64 code.

Lately, I was trying to devise a scheme to protect my plugins from being pirated. Yes, I know it is virtually impossible, but if I could make it harder for hackers to crack my plugins, it would be fine.
I made it work fine in python and in C++, but only in Xcode.

In Windows it is a headache. I only need to be able to access a username/password protected folder in my server and check if there is a file there. I don't even need to read the content of the file (but it would be nice to be able to do that too).

I started out using the cURL library but it is so complicated to make it work. I need 32 and 64 bit versions. Then I also have to include three .dll files in the folder of the application (that means that I would have to ask to the people who buy my plugins to copy three additional files to the main application folder... not a good thing )

So, would anyone point me in the right direction to find a way to access a username/password protected folder on the net? (the username/password is generated in my code so, of course, I know what are the username/password to provide).

Also, I would need a way for the code to be completely self-contained, meaning that the users would not have to manually add any other files (libraries), besides the folder containing my plugin.

And, if the solution was free, it would be great. I'm a freelancer and I don't even sell my plugins for a lot of money.

Thank you all, in advance.

Rui Batista

p.s. I was told that I could use WinInet because all the required .dll files are already included in Windows (from Windows 2000 upwards). Is that correct? If yes, could anyone point me to a simple working code snippet that would allow be to check for the existence of a file in a username/password protected folder in a URL?
If you already have this working on your Mac then the easiest solution maybe to just fix whatever is broken with the C++ part of your solution (although I question the idea of writing an authentication module in a plain text interpreted language like Python).

So I guess the question is, what part of your code is breaking in a Windows environment?
libcurl is the way to go, it works the same on Windows and Mac.
http://curl.haxx.se/libcurl/

You said using curl is complicated, but using WinInet will be a nightmare :)
Look at the most simple curl program:
http://curl.haxx.se/libcurl/c/simple.html

Solution 1:
To use a "username" and "password" just make the URL like this:

original - www.example.com
with username and password: username:password@www.example.com

Solution 2:
Use CURLOPT_USERNAME and CURLOPT_PASSWORD options to curl_easy_setopt() and leave the URL unchanged:
http://curl.haxx.se/libcurl/c/CURLOPT_USERNAME.html
http://curl.haxx.se/libcurl/c/CURLOPT_PASSWORD.html


Try to do this with WinInet if you can :)


As for DLL depedency, do you heard of static linking ? All code is compiled on a single binary, your DLL or EXE, no external library required to run.
Last edited on
I have nothing against Curl, it is probably the better solution. but as far as the DLL dependancy goes, I would opt for a proper Windows installer, i.e. an MSI over statically linking the libraries. This would keep things simple for your clients.
Registered users can post here. Sign in or register to post.