python 保护文件的最佳方法?

发布于 2025-01-10 04:14:11 字数 382 浏览 0 评论 0原文

我想保护一个文件,我不允许用户更改它(只有我的应用程序可以更改它)并且无法删除。我知道 Windows Defender,但它运行得并不完美。 我喜欢这样的东西: 首先我有一个txt文件,该文件的名称是sample.txt,

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

在我运行此代码后,该文件夹为空。

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

这个文件回来了 感谢您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

︶ ̄淡然 2025-01-17 04:14:11

在任何系统上,进程可以执行的操作仅取决于用户 ID,而不取决于应用程序。您想要的只能在类 Unix 上实现,其中应用程序可以在特定用户下运行,这要归功于设置用户 ID 功能。在 Windows 上,唯一可能的方法是拆分应用程序:

  • 一个在专用用户下运行的后端服务,该用户将拥有并编辑文件
  • ;一个用于用户交互的前端应用程序,它将与后端进行通信。服务。顺便说一句,即使在类 Unix 系统上,这也是现在的最佳实践方式。

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.
忘你却要生生世世 2025-01-17 04:14:11

锁定和隐藏文件夹的步骤。

  1. )将您的文件放入文件夹中。
  2. )进入该文件夹并创建一个新的文本文件并将其命名为任意名称。
  3. ) 将以下代码复制粘贴到文本文件中:)
    
    @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. 在文件中查找“在此处输入您的密码”,并将其替换为您的文件密码。
  2. )单击最左上角的文件菜单,然后单击“另存为...”
  3. )将“.bat”扩展名添加到文件名中。例如:如果文件名是locker.txt,则将其设为locker.bat。
  4. ) 单击“保存”并保存文件。
  5. ) 双击locker.bat 文件。将出现一个储物柜文件夹。
  6. ) 将所有要锁定的文件放入该文件夹中。
  7. ) 再次双击locker.bat 文件。
  8. ) 将打开命令提示符。它会询问您是否要锁定文件夹。输入 Y 并按 Enter 键。
  9. )每当您想打开该文件夹时,再次双击locker.bat 文件。输入密码并按 Enter 键。
  10. ) 该文件夹将重新出现。
  11. ) 要再次锁定文件夹,请重复步骤 10 和步骤 11。
    如果您被困在某个地方,请告诉我。

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文