Click here to Skip to main content
15,897,891 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi;
I have an MFC application for Quiz based string comparison that takes user input. This user input is written in the text file during the execution of applicaton. I want this file to be locked once the application is terminated with some password. In other words user playing the quiz should not be able to open the file after playing the quiz. It's like for each question, string should be appended in next line and file gets locked, when next line is to be written file write is unlocked and string is written and then gets locked.
Is there some possible solution for it.
Posted

ufareed wrote:
Is there some possible solution for it.


Try thinking of a different approach.

How about not using a text file, but some other file format and encrypting the data? No need to try and play tricky games with the machine's file system and achieves your apparent real goal of keeping the user from modifying his past answers.

ufareed wrote:
What would be that file format? .docx??


I didn't have a specific 3rd party format in mind.

One possibility that I was thinking of is that some databases allow you to create encrypted databases. I believe both MS Access and SQLite have such capabilities.

The other thing I was thinking of was just to invent your own. Handle the file in binary mode and encrypt/decrypt it (or parts of it) yourself. The situation that you describe doesn't sound to me like it requires particularly high security. If this is the case, you don't need a strong encryption method. You could come up with something simple and easy to implement of your own. On the other hand, you could get go ahead and use the windows CryptoAPI or a 3rd party library.
 
Share this answer
 
v3
Using the FILE_ATTRIBUTE_ENCRYPTED attribute in your initial call to ::CreateFile() will have it encrypted by the system.
Later use ::DecryptFile() to access the contents.
cheers,
AR
 
Share this answer
 
@ Avi
What would be that file format? .docx?? I'll be inerested to know about that too.
 
Share this answer
 
@Alain
Coudl you share some example?
Thanks
 
Share this answer
 

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