Edit: Your revised question makes it clear that you are worried that people editing the code bypass the password check. Yes, it is quite possible. You can deliver your code in .pyc form, but that does not necessarily prevent someone from decompiling and changing it. Unfortunately, Python is simply not designed to prevent code changes. The best you can do is perform some kind of authentication transaction with a secure server, so no matter how someone changes the code, they cannot get around this step. Depending on your specific application, this may be redundant.
The problem of managing password authentication is a complex security problem that people spend their whole careers with. However, there is some information about this that suggests that you are trying to collapse your own authentication with a password:
Even for accidental password protection, as a rule, user passwords are not stored in clear text. Instead, a robust one-way hash function is usually created to create a bit pattern that does not look like a password. When a password is entered, the same hash function is applied and bit patterns are compared. If they are the same, the probability that the password is entered correctly is very high.
What constitutes a "reliable" hash function is complex. Some of them are widely used, and some of the common hash functions are susceptible to known exploits.
Noelkd provides some code demonstrating this approach, although the MD5 that uses its code is (I believe) that has been compromised to the point that there is a better choice. This article also offers some code to do something like this:
Python user and password authentication
If your problem is to save the actual password, which you must pass to plaintext in the SQLite database, this is another problem. In most cases, I saw such passwords stored in clear text both in scripts and in the configuration file, and the application is structured in such a way that compromising this password poses a modest risk.
Mark R. Wilkins
source share