mbrennwa
mbrennwa

Reputation: 611

Software lock key with Python

I wrote a Python program to control a measurement instrument. This program can be transferred to other instruments, but I don't want people to do this without my agreement. I am therefore considering to use some sort of a lock key mechanism, which allows unlocking the software with a key code that is specific to a given instrument. While it's easy to write a bit of code to do this in Python, this code will be visible to anyone and it will therefore be easy to work around it.

Is there a solution for Python to check the key code such that users will not be able (i) to work around it easily by making trivial changes to my code and (ii) to see the code that implements the secret rules to validate the key code?

Upvotes: 2

Views: 284

Answers (1)

Caridorc
Caridorc

Reputation: 6661

Just call a small key-checker program written in C++

#include <iostream>
#include <vector>
#include <string>

int main(int argc, char *argv[])
{
    auto keys = {"Hello World!", "Goodbye World!"};
    
    auto key = argv[1];
    auto authorized_access = false;
    for (auto &s: keys) {
        if (s == key) {
            authorized_access = true;
        }
    }

    return authorized_access;
}

This will make it harder to reverse-engineer as your users will only have the executable. You can use the os package to call the executable and look at the exit code. You can also check that the executable is actually there so that just deleting it won't bypass your key check.

Upvotes: 1

Related Questions