Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to create a 'password.txt' file dynamically.But once created it should not be renamed forever,Is there any way to do this in c#?
C#
string path1 = txtdestination.Text+"password(.txt).enm";
File.WriteAllBytes(path1, keyEncrypted);
Posted
Updated 8-Oct-15 19:59pm
v3

No.
The problem is that the only way to do this is via user permissions - and the admin cab change those at will.
Plus, if a user has read permissions on a file then he can write a new copy under a different name.

Why would you want to do that anyway? If nothing else, I like to have backups - particularly of important files which my passwords would be (if I stored them in text files, which I don't)
 
Share this answer
 
You can do this :

Follow the link http://stackoverflow.com/questions/11318663/prevent-a-user-from-deleting-moving-or-renaming-a-file[^]

Hope it will solve your problem.
 
Share this answer
 
v2
Comments
BillWoodruff 9-Oct-15 2:46am    
The content in that link only prevents a running program from modifing a file it created. That has nothing to do with making the file tamper-proof from other programs.
Try this code,
C#
FileInfo objFile = new FileInfo(path1);
FileSecurity objFileSecurity = objFile.GetAccessControl();
objFileSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.Delete, AccessControlType.Deny));
objFileSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.TakeOwnership, AccessControlType.Deny));
objFileSecurity.AddAccessRule(new FileSystemAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), FileSystemRights.ReadData, AccessControlType.Allow));
objFile.SetAccessControl(objFileSecurity);
 
Share this answer
 
v2
Comments
BillWoodruff 9-Oct-15 2:47am    
So, you use the code you show here ... how does that prevent the kinds of access that the answer above by OriginalGriff describes ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900