0

I am writing a script that allows users to use a USB stick as a 2FA Login Key on their computer, but if they accidentally delete the key on the USB their computer would potentially permanently log them out, so i would like to make the key file undeletable by the user. Is there a way to set user access rights with a file in python?

Can I make the drive read-only in python, or are there any other solutions to stop the file being deleted? Can I do this in the write of the file below:

def create_config(path):
    # Generate random key
    random_key = create_login_key()

    # Write random key and file path to config file
    config = open('config.ini', 'w')
    config.write(f'[DEFAULT]\nRandomKey={random_key}\nFilePath={path}\n')
    config.close()

What I have tried:

I cannot find any documentation on doing this, except an old python 2.0 stack overflow thread, so I don't know if it is possible in python 3.11 anymore.

Dan Biz
  • 1
  • 1

0 Answers0