Put password in a python file

2

I'm doing a program in which you select the file you want to block using a password, by clicking a button that file is locked with a user-defined password. How can I make this file accessible only with the password?

    
asked by anonymous 04.04.2017 / 20:07

1 answer

1

I believe you can use a library such as PyCrypto to encrypt and decrypt your file with a password.

Take a look this topic and on this too.

Create a function for proteger() and one for desproteger() , which receives both the file path and the access password.

  • proteger('arq.txt', 'senha_dificil123')
  • proteger('arq.txt', 'senha_dificil123')

Just read documentation to understand how to perform these procedures.

Another alternative would be to create a function to compress the file and put a password to unzip the file, as shown in this topic .

To create an encrypted file 'meu_arquivo.zip 'using the open source solution 7-Zip :

x = subprocess.call(['7z', 'a', '-pP4$$W0rd', '-y', 'meu_arquivo.zip'] + 
                     ['arquivo1.txt', 'arquivo2.txt'])

To install 7-Zip :

No Linux , to install type in the terminal:

$ sudo apt-get install p7zip-full

To manually unzip the created file, type: $ unzip meu_arquivo.zip and type 'P4$$W0rd' at the prompt that appears asking for the password.

In Windows , just run the installer .exe .

    
04.04.2017 / 22:09