如果用户更改系统日期然后我如何获取Windows应用程序中的当前日期 [英] If User Change The System Date Then How I Get The Current Date In Windows Application

查看:101
本文介绍了如果用户更改系统日期然后我如何获取Windows应用程序中的当前日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Windows应用程序。我正在使用DateTime.Now.ToString(MM / dd / yyyy);获取当前日期。如果我更改系统日期,DateTime.Now()返回的日期也会更改易受攻击的日期。



任何人都有解决方案吗?谢谢

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

推荐答案

避免此问题的唯一方法是从用户无权访问的服务器(可能是数据库)中读取日期,以更改日期和时间。



或者,使用互联网从某个外部时间服务器获取日期。
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.


这是它必须要去的方式。 DateTime.Now从客户端的机器返回当前时间,你不能忽视这个关于.NET的事实。



你可以做的是从你自己的服务器上获取DateTime。这将最小化获得不准确时间的错误。尝试使用DateTime.UtcNow在您自己的服务器上获取Utc计时。这样,您可以将服务器上的实际日期时间和用户的日期时间保存在单独的AppData文件夹的文件中。在每次执行之前比较日期时间的位置。



但是还有很多其他方法可以获取准确的日期时间,请看这个 [ ^ ]网站。你也可以从那里得到时间。



但是即使在客户端计算机上执行的DateTime.UtcNow也会将DateTime对象转换为从系统日期时间返回的DateTime对象的Utc类型。



记住:你不能阻止用户做任何事情。 Windows会让他,你的工作变得悲观,以确保这些事情。他会做许多你需要注意的邪恶事情:D
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


尝试从外部服务器加载日期时间并在客户端显示。通常只有具有管理权限的用户拥有更改日期/时间的选项。
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.


这篇关于如果用户更改系统日期然后我如何获取Windows应用程序中的当前日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆