• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get current time value?  RSS feed

 
Puspender Tanwar
Ranch Hand
Posts: 499
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a requirement where I have to set expiry date for a product's trial version. As of now, I am using Calendar class for getting the instance of current date and time. But this approach is system dependent, suppose I put 20Nov,2017 as the expiry date, now if the user changes their system's current time to some date of 2016, he will get the trial version for 1 year. And using this loophole he can get lifetime access to the product.
Is there any library which can solve my purpose? Below is the code I am using:
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you really want to protect against someone changing the system date and time, it's not going to be simple. Certainly not as simple as calling a different library method.

If you would really want to do this, you would need to go and ask the current date and time from a server on the Internet, preferrably one that you control yourself, where you can make sure that it knows the real current date and time.
 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you can't get the value from a time server, you should really consider using the new Java 8 Date/Time API if that's an option.
 
Puspender Tanwar
Ranch Hand
Posts: 499
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Junilu & Jesper.
I think the best approach for me would create a Time Server, and I did it as well.
I wrote a code on the server which returns the server's current Date-Time. As of now, I just ran the java program on server's terminal(and kept the program running) and tested that from my local. But I don't think, this is the approach to achieve such things, as I cannot be sure if that program will keep on running on that server. I believe there is something else I can do, but I am not aware of that concept.
Below is the server and client code I have written:

 
Junilu Lacar
Sheriff
Posts: 11477
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can always keep a list of known NTP servers (see http://tf.nist.gov/tf-cgi/servers.cgi) and go through the list until you find an entry that succeeds. If you have enough servers on your list and none of them are available, then you have bigger problems than just getting the time of day.
 
Knute Snortum
Sheriff
Posts: 4274
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are ways to get your server to run in the background and startup automatically, depending on what kind of OS the server is.
 
Puspender Tanwar
Ranch Hand
Posts: 499
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to pass the user's TimeZone as String as per below updated program and printing that timeZone on server's console. But program is doing nothing, just keep on waiting.
What am I doing wrong?

The server side code :

Waiting For Connection ...
got connection

is printing on the server console, and then nothing is happening. Niether server is returning something nor printing anything on console.
 
Dave Tolls
Ranch Foreman
Posts: 3056
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your client is doing osw.write().
Your server is doing reader.readLine().

readLine will block (or keep reading) until it encounters a new line character, or the end of stream.
Neither of which are being sent.
 
Puspender Tanwar
Ranch Hand
Posts: 499
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:Your client is doing osw.write().
Your server is doing reader.readLine().

readLine will block (or keep reading) until it encounters a new line character, or the end of stream.
Neither of which are being sent.

Dammm, how can I do this stupidity !! 
Thanks Dave.
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Puspender Tanwar wrote:I wrote a code on the server which returns the server's current Date-Time. As of now, I just ran the java program on server's terminal(and kept the program running) and tested that from my local. But I don't think, this is the approach to achieve such things, as I cannot be sure if that program will keep on running on that server.


But if you're going to be distributing a product and you want to build in a feature whereby it has a trial version and a full-featured version, then one would assume that money is involved. And if there's enough money involved that it actually matters, then you could certainly spend some of that money on a server which enforces the trial period. Or alternatively you could decide not to spend that money and assume that most people aren't going to fiddle with their computer's clock just to get around the trial period. Either would be a valid approach.

However if you do decide to provide your own server, then you must make it reliable. Otherwise people who have paid for the full-featured version will be cheated when your server is not responding.
 
Puspender Tanwar
Ranch Hand
Posts: 499
2
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:But if you're going to be distributing a product and you want to build in a feature whereby it has a trial version and a full-featured version, then one would assume that money is involved. And if there's enough money involved that it actually matters, then you could certainly spend some of that money on a server which enforces the trial period. Or alternatively you could decide not to spend that money and assume that most people aren't going to fiddle with their computer's clock just to get around the trial period. Either would be a valid approach.

Yes, I will deploy this code on a server only, which can be publicly accessed. I will create a jar file and will run it from Window's task scheduler.Will it be the correct approach for my purpose?
Paul Clapham wrote:However if you do decide to provide your own server, then you must make it reliable. Otherwise people who have paid for the full-featured version will be cheated when your server is not responding.

Generally, we(at my work) handle trail version product differently. There is an Oracle middleware tool(ODI) for which we make this product. And for the new customer, we provide trial version product by putting a code on the initial steps of that(the first code in this thread) and encrypt the whole code using ODI only. And when a customer buys the product we remove that code. But since it is a system dependent solution, I thought to handle it differently and came to this thread.

I have wrote some more code that will calculate if the trial version is expired or how many days are left(in actual it's not hardcoded values):

But the output is coming as:
User current date is: 2017-11-17T13:17:32.034
expiry date is: 2017-11-18T23:59:59
is Expired: false
Time left : 1days 34hrs2082minutes

How can be time left be such?
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with that? There are indeed 34 hours (and a bit) between those two times. Likewise there are 2082 minutes (and a bit) between those two times.
 
Tim Holloway
Saloon Keeper
Posts: 18789
74
Android Eclipse IDE Linux
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The more energy you spend on "protecting" your product, the more it will cost you in ill will on the part of both your actual and possible future customer base since it's a virtual guarantee that the protection system will make the product harder to work with. Plus going to extreme measures not only sucks development resources from the actual revenue-producing parts of the project, the extra complexity increases the potential for bugs in the system.

I'm anticipating the day when a famous surgeon damages a tendon and ruins his career opening one of those infamous "laceration pack" product packages. You know them, they're the hard plastic shell that protects cheap products from theft and when the legitimate purchasers try to open them, they have to deal with slipping surfaces and sharp edges. A wealthy doctor with a lawyer can do terrible things to a company.

The "stop loss at all costs" attitude is also why I don't shop at stores like Wal-Mart where there are more security people checking your receipts at the door than there are people manning the cash registers 5 feet away from that door.

I will confess that I have done a little clock-fudging in my time, but anything really worth serious use eventually got bought.

Locks are for honest people. It's true. An honest person will buy a key just because it's the Right Thing To Do and because licensed users find it easier and more profitable to work with an unlocked system. Not to mention support. Red Hat doesn't actually "sell" their OS products, but they're a phenomenally successful company because people are willing to license their support (disclaimer: I've owned stock in them for years and it's one of the most profitable investments I've made by far). In fact, Red Hat actively supports the CentOS group, which makes most of the RH product line available to anyone absolutely free for those who don't/can't/don't want to pay for support.

Dishonest people, on the other hand, will crack your protection system and laugh at you. I've even worked in a shop where our developer cracked copy protection simply because the company we were collaborating with was limiting his productivity on building the system add-ons.

Sometimes a technical solution is not the best solution.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Google has a service here: https://developers.google.com/time/
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!