I need to add a license check to the program. I have a set of keys and a function that checks their validity. I do not know how best to connect it with int main and how to check the keys (i.e., you need to somehow store them and take them from somewhere).

    1 answer 1

    Well, apparently, this is not your banking system, and you will not suffer from hacking (unless morally), so you just write a function like

     bool checkKey(const string& key); 

    which then in main is called like

     int main() { string key; cout << "Enter key: "; cin >> key; if (!checkKey(key)) { cout << "Wrong key!\n"; return 1; } 

    Well, the function itself, for example, can check the presence of a key in the file with the issued keys, or, for example, the key must have some special properties - such as, some checksum must have a certain value, or the sum of digits for even and odd the places to coincide (or differ, say, on 13) - in general, what will come to mind, create and verify such keys.

    Only, of course, this is all easily broken, but once again - judging by the question, it is not a serious task of protecting the supersoft from any other coolers :)

    • Yes, it is clear, this is protection from schoolchildren I already have a checkKey , I just have to store the key over time so that I don’t ask every time I start it. - Poul Shipilov
    • Now they are doing activation over the web. Store on a remote server — send the key over an encrypted channel, so as not to be protected from schoolchildren. - GarfieldCat
    • @GarfieldCat I know, but the servers from the database are all paid, so it could be - Poul Shipilov
    • 2
      @PoulShipilov To safely store the password "on your computer", you need to use the API provided by the operating system. For Windows, see CryptEncrypt and everything nearby. The system will "encrypt" a password that can only be decrypted under this account. For iPhone, for example, encrypted storage is tied to an icloud + program or icloud + vendor. - ffk
    • Difficult of course - you can make a dll in C # to work with Google Drive and work with a dll from C ++ - Pavel Gridin