Home > Mobile >  Best way to protect file python?
Best way to protect file python?

Time:02-26

I want to protect a file , i don't allow user can change it (only my app can change this) and can't delete. I know Windows Defender but it's not work perfect. I like something like this: first i have a txt file, this file's name is sample.txt

from protector import protect_with_lock
protect(file="sample.txt",password_lock="12345")

after i run this code this folder is emty.

from protector import unlock
unlock(file="sample.txt",password_lock="12345")

and this file is come back Thanks for help!

CodePudding user response:

On any system, what a process can do only depends on the user id and not on the application. What you want would only be possible on a Unix-like where an application can run under a specific user thanks to the set user id feature. On Windows, the only possible way is to split the application :

  • a back end service running under a dedicated user that will own and edit the file
  • a front end application for user interaction that will communicate with the back end service. BTW this is now the best practices way, even on Unix like systems.

CodePudding user response:

Steps to Lock and hide a folder.

  1. ) Put your file inside a folder.
  2. ) Get into that folder and create a new text file and name it anything.
  3. ) Copy paste the below code inside the text file:
    
    @ECHO OFF
    
    title Folder Locker
    
    if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
    
    if NOT EXIST Locker goto MDLOCKER
    
    :CONFIRM
    
    echo Are you sure u want to Lock the folder(Y/N)
    
    set/p "cho=>"
    
    if %cho%==Y goto LOCK
    
    if %cho%==y goto LOCK
    
    if %cho%==n goto END
    
    if %cho%==N goto END
    
    echo Invalid choice.
    
    goto CONFIRM
    
    :LOCK
    
    ren Locker "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
    
    attrib  h  s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
    
    echo Folder locked
    
    goto End
    
    :UNLOCK
    
    echo Enter password to Unlock folder
    
    set/p "pass=>"
    
    if NOT %pass%==Enter-Your-Password-Here goto FAIL
    
    attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
    
    ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" Locker
    
    echo Folder Unlocked successfully
    
    goto End
    
    :FAIL
    
    echo Invalid password
    
    goto end
    
    :MDLOCKER
    
    md Locker
    
    echo Locker created successfully
    
    goto End
    
         :End
  1. ) Find for 'Enter-Your-Password-Here' inside the file and replace it with your password for the file.
  2. ) Click on file menu on the left most corner and click on 'Save As...'
  3. ) Add '.bat' extension to the filename. For ex : if the filename is locker.txt, then make it locker.bat.
  4. ) Click on save and save the file.
  5. ) Double click on the locker.bat file. A locker folder will appear.
  6. ) Place all the files to be locked in to that folder.
  7. ) Double click on the locker.bat file again.
  8. ) A command prompt will open. It will ask if you want to lock the folder.Type Y and press enter.
  9. ) Whenever you want to open the folder, double click on the locker.bat file again. Enter the password and press enter.
  10. ) The folder will reappear.
  11. ) To lock the folder again, repeat step 10 and step 11. Let me know if you get stuck somewhere.
  • Related