In my Delphi Windows application i need to login every day.
at first i used system date (11-11-2019) and i compare system date to stored one every time on OnCreate if date is different i call login.
But the system time can be paused right ? Then i thought of server time but checking server time on every OnCreate is not efficient i think as my app launches many times.
Can't use token based system to check as i am using firebase REST-API backed and it's token is expired in every one hour however if i use token based i still need to compare it and the system time might be paused.
How to effectively check if date is changed ?
The inapp time is short as the work is done in 10 seconds and the form may be then closed by user and the next app start time may be less a minute so why call for the server time again ?
You can check the current date and time querying a NTP server.
See this answer for more details.
Related
I'm developing an application in Flutter for online queries and right now I'm lost as to how to show the user, for example, a message based on the exact time he previously chose. The user can already choose the day, month, year and time, and after he selects them, I can store them as Strings, but I don't know of any tool that can perform some function at that exact moment. What I want to do is that after entering the information of the day and time of the consultation, a notification appears to the user asking him if he wants to join the video call, but only at the time he chose.
I tried to calculate the difference between the chosen date and the current moment, and based on that duration I used the Timer to execute some task after the elapsed time. But I was also in doubt if this function would be executed even if the user had not opened the application, so I don't know if it would really work or not. Previously I also researched dependencies that could help, I found for example the sf_calendar, but from what I observed it only has a system to choose the date and save and display this data on the screen, but it does not allow performing some function on that date.
Can Firebase get accurate time for offline records which have been stored in device when the device's clock has been changed? The device's clock might be changed when the user rebooted the device or when the user adjusts the date time manually.
My case is quite similar to Get actual DateTime of a device in Offline Mode which I can quote here 1) The application can work in online as well as offline. The app has a feature to create and save the NOTES inside the application. Also, When the app gets internet connection, I need to send the NOTES to backend server. I have a field called 'DATECREATED' in each NOTE (the datetime where the actual NOTE was created) ISSUE: If the User has set the DateTime wrongly in the device, My application sends the incorrect DATETIME to server.
I am going to handle the offline issue on Android and IOS platform, so I came out with another possible solution such as get the GPS time, using some sort of background counter, etc. Based on my experiment, the solution are not reliable enough and some might difficult to do. That's why I decided to get the accurate timestamp using Firebase.
I read a reference https://firebase.google.com/docs/database/flutter/offline-capabilities#clock_skew, but I am not quite sure whether it can help me to get accurate time for offline records.
There is no way you can get a server timestamp while offline. Why? Simply because the timestamp is totally generated on the server. And since you're offline and cannot communicate with the server, you cannot get an estimation. So there is no other system that can generate a timestamp other than the Firebase server.
Besides that, a date that can be generated on the client can be manipulated, so you cannot rely on that.
The option that you have in my opinion would be to have two fields. One is for the real timestamp, which you'll be received when you're back online and the other one is what the client provides. In that way, you make a comparison, if this is what you want.
Edit:
Firestore, is a Cloud hosted NoSQL database. So there is no way you can generate an accurate time while the user is offline. What you can certainly do is calculate the period of time while the user is offline. This means that you have to calculate the number of minutes the user has lost connectivity. Let's say a user losses connectivity for 10 minutes, when it regains connectivity, you receive the Firestore timestamp. Now, all you have to do is to subtract those 10 minutes from the received timestamp in order to have the accurate time that you're looking for.
A mobile app has a check-in feature for the user to send a photo and observation and the app will append his location, date and time to the request, and send it to the server.
It is extremely important that this date and time is not faked by the user, or else the user will be able to be late at work but check-in with a fake "15 minutes ago".
The server is in USA, and the users are in many countries so there are different date and timezones, for that reason I think I can't use server date and time.
That check-in is visible in a website to users all around the world, but the check-in time must be the one from the user who made it.
Example
User checks-in at 5th July 13:45 in Mexico.
Website should show this date and time, 5th July 13:45, even if it's visualized by someone in Japan.
Problem
User checks-in at 6th July 09:37 in Brazil, but he fakes his mobile date and time settings to say it's 6th July 09:00 to pretend he's not late for work.
How can the sever know it's actually 6th July 09:37 and not 09:00, and show that correct date and time to whoever sees it anywhere in the world?
Keep in mind that user can also fake his timezone and GPS, still the server needs to get the real timezone to show real and not mislead information.
It is extremely important that this date and time is not faked by the user, or else the user will be able to be late at work but check-in with a fake "15 minutes ago".
This part is best handled by taking a UTC timestamp from the server when the request is received.
The server is in USA, and the users are in many countries so there are different date and timezones, for that reason I think I can't use server date and time.
Time zone is irrelevant for this purpose. Get the UTC time from the server, not the local time. The local time of the server should not ever be used in your application code.
If you need to adjust it to a particular time zone, then you can collect that from the user in a variety of ways, or you could assign one permanently to the user by some administrator of your application. Even if the time zone is wrong or faked, it won't affect the duration of time worked - because you captured that in UTC.
Example
User checks-in at 5th July 13:45 in Mexico.
Website should show this date and time, 5th July 13:45, even if it's visualized by someone in Japan.
That's fine. Save that the user is in Mexico (... actually, Mexico has several time zones, so you'll need to be more specific - use an IANA time zone identifier). You can convert the UTC timestamp to Mexico time whenever you like - either when you recieve the timestamp (saving both UTC and Mexico time), or when you display it to the user (saving only UTC and converting to Mexico time at the time of display). That the user is in Japan is also irrelevant to this scenario.
Problem
User checks-in at 6th July 09:37 in Brazil, but he fakes his mobile date and time settings to say it's 6th July 09:00 to pretend he's not late for work.
That's not an issue if you capture the time in UTC at the server and make sure your server's clock is synchronized properly.
Keep in mind that user can also fake his timezone and GPS, still the server needs to get the real timezone to show real and not mislead information.
Indeed. You can't capture this information from the user in a way that can't be falsified. However, you can avoid relying on this in your application code. For pure duration calculation, just base everything on UTC. For more complex things (like determining shift differentials or daily overtime working over midnight or at other peak local hours, etc.) then have some other user set the time zone that's applicable rather than collecting it. For example, assuming these are employees, the employee's manager or HR department would assign a time zone to the employee's personnel record.
Of course, if the employee is traveling for their job, and local time rules apply differently in different time zones, then you have even more logic to think about how you capture such details. (My experience tells me this is rare.)
You can't do what you want to do. Your app relies on the mobile device's OS to get things like date, time, timezone and gps. While it's harder to fake gps data on out of the box OS's it's always going to be possible. What you really want is a "backdoor". A backdoor that will let you get to the user device's "real" information no matter how hard the user tries to hide it. If that were possible we wouldn't need/have hackers and government cyber security teams. Anyone who knew the backdoor could just find anyone else in the world.
You can only try to catch such abusers using some of your own measures. You can check if the users time zone is changing. Or using an ip address from a different country since the last time he/she used the app. Or if you're really going to ask for gps permission, you can also see if that person's location over time doesn't make sense (E.g the user was in Canada but 3 hours later it looks like they're in China). Once you detect such possible abuse, you can flag the account for human review.
I am developing an application that must work online and also offline. This application should sync informations with our server. For this, we need that the device utilize the server clock.
I found a lot of information, and I get the following idea:
When the user logins online I will force him to get the server clock time. In this moment he obrigatory must have internet connection, so it is ok.
When I get the clock server time, I get the systemUptime information that says the interval that the device is turned on, and I store it. I can get systemUptime like this:
[NSProcessInfo processInfo].systemUptime
When the user to create a new local file, I will know the current interval based on systemUptime function, so I know the current time, and I don't depend the iOS system clock.
The problem is: Everytime that device is rebooted, or turned off, the systemUptime is reseted. Until here OK, I can solve it forcing the user to login again, and getting the server clock time again. My problem is to know when the device was rebooted. Can you help me? Thank you guys!
My advice would be to not refer to the device time at all. Get the the files from the server and have the server also answer the server time that the files are retrieved. You can store this in the file, in the file name, or separately on the device.
At some point in the future ask the server if there's a file newer than the server time you recorded earlier.
In this sense, the time isn't really a time at all, it's a version number, and you could make that explicit with the server too, using just an integer from the server that indicates progressing sequence of versions.
If it's important that your app be strong in this way, your only choice is to remain independent of device time. Otherwise, there are too many ways it can break (including small time errors due to latency on the time check, or device factory resets or malicious actions by a user). It's better to remain independent of device time if you can.
When you get the systemUptime the first time, subtract it from the current (iOS) date and time. That's the time the system was last brought up.
Then recalculate this value whenever necessary. If the "time the system was last brought up" has changed, then you know it's time to log in again.
However, as suggested by another commenter, I suspect there's a better way to tackle this from scratch.
hi i am making an app in which user sends xml to server and get response....
now i have to save the date and time of sending and response of that request....for this should i use iphone's date or check it online?
because my thinking is that the iphone's date and time may not be correct.....always...so it is better to check the time online ....
i know the local part but need help regarding online check....please help
Just use the local time. It will save you a lot of trouble and work. Or is your app so absolutely dependent on the correct time, like to display the current position of the sun or something ? If not, the local time is likely "good enough".
If you need the same time as the server, then it would seem that you need to establish the offset between server time and local time, and then you can adjust your local timestamp.
Is there a way to get the (current) time from the server?
Assuming the timestamp you're saving is for the request sent from the iphone and the response received by the iphone, then it would actually seem logical to use local (iphone) time.
You could always use NTP (http://en.wikipedia.org/wiki/Network_Time_Protocol) to get the current time, but that doesn't guarantee the time is thesame as the server.
You usually don't need absolute time of some sort, just the same time source as your server and your server's database.
So compare your local time with whatever the server thinks the time is and adjust accordingly.