Last modified time in file.
-
Hi, I don't know from which heaven I got this idea of storing last modified time in side the XML file, as a node. But I will tell you why I need this, and can you tell me how am I suppose to do it. I want to prevent user to hack my file, they shouldn't be able to modify it and save it. If they do that, I delete that file and recreate a newer one. (Like giving monkey a banana locked inside a transparent box, he can see it but can't eat it :) ) But to accomplish this I need to store the last modified time in the file and on save do not modify the last modified time. If I am sounding crazy, let me know I will explain with an detailed example. Thanks for you Precious time, Karmendra
-
Hi, I don't know from which heaven I got this idea of storing last modified time in side the XML file, as a node. But I will tell you why I need this, and can you tell me how am I suppose to do it. I want to prevent user to hack my file, they shouldn't be able to modify it and save it. If they do that, I delete that file and recreate a newer one. (Like giving monkey a banana locked inside a transparent box, he can see it but can't eat it :) ) But to accomplish this I need to store the last modified time in the file and on save do not modify the last modified time. If I am sounding crazy, let me know I will explain with an detailed example. Thanks for you Precious time, Karmendra
I got it, this,
File.SetLastWriteTime(FileName,LastWriteTime);
would do the job. Thanks.
-
I got it, this,
File.SetLastWriteTime(FileName,LastWriteTime);
would do the job. Thanks.
That might only stop casual users, and it could cause the file to be deleted even if no changes were made. I can write something that does the same thing and bypasses your "security". You would likely have to store the date somwewhere inaccessable. Or encrypt the date and a hash of the file or something. I wouldn't bother trying to "secure" the file this way. Even Visual Studio doesn't. When I modify a file (even project files) with Notepad it merely asks if I want to reload the file and accept the "unauthorized" changes.
-
That might only stop casual users, and it could cause the file to be deleted even if no changes were made. I can write something that does the same thing and bypasses your "security". You would likely have to store the date somwewhere inaccessable. Or encrypt the date and a hash of the file or something. I wouldn't bother trying to "secure" the file this way. Even Visual Studio doesn't. When I modify a file (even project files) with Notepad it merely asks if I want to reload the file and accept the "unauthorized" changes.
I am doing this not for cs files but my own configuration file, and it is not if user see the data but if he modifies it it will be replaced with default. i am storing a checkbox value true or false. Actually I am no good with encryption, I wasn't able to choose one to use. I actually don't want the user to modify the config file outside of my application. Can you tell me other ways to prevent it? Thanks for your words. Karmu
-
I am doing this not for cs files but my own configuration file, and it is not if user see the data but if he modifies it it will be replaced with default. i am storing a checkbox value true or false. Actually I am no good with encryption, I wasn't able to choose one to use. I actually don't want the user to modify the config file outside of my application. Can you tell me other ways to prevent it? Thanks for your words. Karmu
KSuthar wrote:
Can you tell me other ways to prevent it?
No, I can't think of a way to be sure. And I don't think it's a reasonable goal. If the user wants to modify the file outside the application, why not allow it? It seems to me that the application needs to: 0) Check that the file exists 1) Load it into an XmlDocument 2) Check the schema 3) Read the value and confirm that's it either True or False 4) If anything in that process fails, then use the default, otherwise you got a valid value, why do you care how it got there? You might also consider a binary file rather than an XML (text) file, to make modification more difficult.