Reputation: 81
I am making a small game at the moment, and want it to be possible for users to save their characters, which will likely be stored in a text file. Is there any way to make this text file inaccessible to the user in the windows explorer or whathaveyou, so that save tampering is impossible (or at least harder), but also accessible to my program?
Upvotes: 4
Views: 935
Reputation: 2361
What you are asking is functionally impossible unless your game or a daemon runs as a different user that the player's windows account has no access to. This is normally not the case as the player probably has administrator access to his or her own computer. There is really no way to fully secure the file from a savvy root/administrator user without an external service that would hold a secret key as far as I know.
Some steps you could take to make it harder to change a file: Save the file then generate a checksum, md5, sha2, or use some other hashing function to hash the file. Then Store the hash in a separate file (or tack it on the end of the one you wrote).
When you read the file, you run what you read through the same hashing function and ensure that the hash is the same as the hash you stored with the file.
This of course can be hacked by a savvy user but is a pretty good way to deter people from messing with the game file
Upvotes: 1