2

On Python, I was wondering if there was a simple way to create a text file which can't be edited by the user and can only be edited once, by the computer.

I want to use this so that I can make a User ID for a user that cannot be changed. Does anyone have a solution?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
JohnyNich
  • 1,221
  • 3
  • 14
  • 23
  • 2
    The user can't edit? Sure, use `chmod` and `chown` given that the user does not have administrator / root privileges, he should not be able to edit if you set the right permissions. The system can't edit? Well, a root user / system, will always be **able** to change / modify the file, but if it **will**, depends. – shad0w_wa1k3r Mar 19 '17 at 10:15
  • Also, since you only want to generate an ID, given that you have the username, you could just MD5 or a SHA hash. – shad0w_wa1k3r Mar 19 '17 at 10:17
  • I just want the simplest way possible. All I need is for it to write the ID to a file and then "lock" the file. – JohnyNich Mar 19 '17 at 10:19
  • 1
    No, there isn't. You cannot trust the user's computer. If it's important, store it on your server. – jonrsharpe Mar 19 '17 at 10:19
  • Possible duplicate of [Changing file permission in python](http://stackoverflow.com/questions/16249440/changing-file-permission-in-python) – kiner_shah Mar 19 '17 at 10:20
  • @jonrsharpe Don't have a server and I'm using the ID for a small project of mine. – JohnyNich Mar 19 '17 at 10:24
  • Then what is the ID for? What does it relate to? Please provide some useful context. – jonrsharpe Mar 19 '17 at 10:25

1 Answers1

1

If there is any security reason why the UserID shouldn't be changed then you need to store the information on your own server. If you don't want it to be easy, but don't mind it being possible, then you could either change the file permission on the file, encrypt the file in some way so that it's not easy to edit by the user, or hide it by prefixing the name with a . so that it doesn't automatically appear in the explorer window.

Community
  • 1
  • 1
Ari Cooper-Davis
  • 3,374
  • 3
  • 26
  • 43
  • 1
    Thanks a lot! I was thinking about some of those options before but thanks for some of the other suggestions. – JohnyNich Mar 21 '17 at 02:31