Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am working on a windows application. I am using DateTime.Now.ToString("MM/dd/yyyy"); to get the current date. If i change the system date the date returned by DateTime.Now() also changes which is vulnerable.

Any one has a solution for this? Thanks
Posted

The only way to avoid this problem is to read the date from a server (maybe database) to which the user does not have access to change date and time.

Alternately, use the internet to fetch date from some external time server.
 
Share this answer
 
This is the way it has to go. DateTime.Now returns the current time from the client's machine and you cannot ignore this fact about .NET.

What you can do is, to get the DateTime from your own server to work on. This would minimize the error of getting the inaccurate time. Try using DateTime.UtcNow to get the Utc timing on your own server. This way, you can save the actual datetime on your server and the user's datetime in a seperate AppData folder's file. Where you compare the datetime before each execution.

But there are many other methods for fetching the accurate date time, have a look at this[^] website. You can get time from there too.

But even the DateTime.UtcNow that was executed on the client's computer will give the DateTime object that will be converted to Utc type of the DateTime object returned from his system's datetime.

Remember: You cannot prevent the user from doing anything. Windows would allow him to, its your job to be as much pessimist to be sure about these things. He will do many evil things that you need to be carefull about :D
 
Share this answer
 
v2
Comments
ErBhati 4-Nov-14 6:21am    
Nice suggestion.
Afzaal Ahmad Zeeshan 4-Nov-14 6:30am    
Thanks ErBhati.
Try getting the date time loaded from an external server and display in client .Generally only a user with administrative privilege have the option to change date/time.
 
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