Reputation: 2611
I want to generate a serial number for an application (to be used just in a period of time), this serial number based on the time, so it's will be unnecessary code if change the clock time in my computer so am asking you if is there any possibility to get the real DateTime even if i changes time on my computer using C# ?
(I assume that the user does not have an internet connection)
Upvotes: 1
Views: 1424
Reputation: 9772
What people do: Record the time (of local clock) when your program was executed somewhere in the registry (or another hard to guess place).
If your program runs again and finds local time being before this recorded timestamp it refuses to start.
This is a method to prevent users from manipulating the clock in order to reactvate your license.
You'll have to consider chages in daylight saving time, so you should allow one hour of "time jumps"
Upvotes: 2
Reputation: 1500595
am asking you if is there any possibility to get the real DateTime even if i changes time on my computer using C# ?
(I assume that the user does not have an internet connection)
No. The system clock is the local source of time information. If you can't go to a reliable external source (due to a lack of internet connection) there's nothing else you can rely on.
I suggest you use an internet connection to check the time if there is one, otherwise fall back on the system clock, possibly detect time having been reversed significantly (if at one point you "see" the time as April 20th, and then at another you "see" the time as April 15th, you can assume something odd is going on) and accept that a sufficiently motivated user will bypass the check.
Upvotes: 8