4

I am distributing a PHP created plugin like a Wordpress plugin but I want to implement an API key for it and users would need to enter an API key to unlock it for it to work.

How can that be done? And yes I already know it could be easily bypassed since PHP is not compiled but atleast it will deter some people with no PHP knowledge.

Thanks..

9
  • It won't really even deter them; those will the knowledge will remove the check and make that version available; those without the knowledge will use that instead - see all those movies that were once on DVD with encryption beyond most users' abilities to remove, but easily reached now without any encryption at all. Commented Dec 14, 2010 at 3:20
  • What exactly do you mean by an API key? The traditional usage is along the lines of "a secret component of a URL that you use to automate actions" but it sounds like you mean "product key". As for the question itself, you're right - it would really be a waste of time, and you don't need to know PHP to google "[your app] key bypass" Commented Dec 14, 2010 at 3:20
  • @El Yobo..actually it will deter them...I have seen many plugins have this API key...The point here is I don't really care if it does or does not deter them but I just want this feature.. Commented Dec 14, 2010 at 3:24
  • 4
    I don't want to be nitpicky, but I believe you mean License Key. Commented Dec 14, 2010 at 3:28
  • 1
    Rick, Akismet is actually a real API key. It uses this API key to communicate with the Akismet server to obtain data. What you are describing is a License key. Unless you are using this key to communicate with your server to obtain some sort of data? Commented Dec 14, 2010 at 3:50

4 Answers 4

6

I don't think you understand what an API key is.

An API key is a key that allows you or a script to access and interact with an API or an online service.

What you seem to be describing is some sort of license key, that would prevent a user from operating your script without perhaps payment or registration.

While an API key often does require payment or registration, the two are really not the same thing.

API keys are typically put into place to track the use, and prevent abuse of online services and data.

It appears that in your case you are simply trying to restrict access to your script.

Unless your script has a fundamental dependency on a remote data source, this method will not work because any user with any distant knowledge of PHP will just remove the code that performs the validation.

With PHP, the same applies to a license key. User's will find a way to circumvent it, unless they need it for the script to perform.

The validation must be performed remotely, and there must be some incentive to leave it in-tact (access to remote data being the obvious one).

Sign up to request clarification or add additional context in comments.

4 Comments

Yeah, he is talking about a license key.
sorry no i am talking about all the other plugins on wp that uses api key...they do it the same way..you buy the plugin, a unqiue key is sent to you..thats it...and you active the plugin with the key.. I dont know why you guys keep referring to it would be easily cracked...who cares? most people who will buy a simple plugin to use WILL NOT know how to crack it..the ones that know how, wouldn't even purchase this as they can make it themselves...
What you are trying to accomplish is impossible to implement in a legitimate and secure fashion.
Dont be silly, as mentioned 3-4 times, this is done by developers of WP plugin all the time...It is not "really" meant to secure anything...it is just a simple activation before the plugin works...that's it, nothing more nothing less...and most importantly to track who is using it...
1

You can scramble the actual source code with the API key. Encrypt some essential part of the source code (e.g. using libmcrypt), and have the script load and decrypt the source. Of course, somebody finding the relevant routine could then easily dump the source to disk and use that instead, but it won't be as trivial as removing a check.

1 Comment

Thanks for the suggestion however that is already more advance than I need...What I am thinking from logically point of view is I can generate a set of keys and after the software is installed, a database is created...when the user gets the key, they will enter it into the software and it activated the whole program which in turns puts the key into the database. During activation, the key they entered is checked against a server somewhere...
0

Its absolutely pointless. As its php you have to send the source code and any user can just remove the license check code and run it.

Besides people don't like messing with license keys unless you software is really, really useful, desirable or essential they will either find a license key free alternative or just not bother with it.

3 Comments

sorry you're wrong...i have used plugins that have api key for many clients and all of them has come back to me to buy new keys...If any of them (about 35 people) knows how to just bypass the check, you think they won't? because they don't know how...the ones that know how, won't buy this plugin...this plugin is for end users that don't know php from C++...
@Rick, if you've done it before, just do whatever you did last time.
No I have not done it before..that was not developed by me...I am just an affiliate selling for them...now I want to create my own plugin...
0

If you don't care about people removing your check then you really only need to add a if statement that validates if the configured license key is valid or not.

I noticed you mentioned your license keys were simply SHA1 hashes. You could easily append an extra 4 characters to the hash, which you could use as checksum.

For instance:

function generate_key()
{
  $serial = sha1(uniqid(rand(), true));
  $checksum = substr(md5($serial), 0, 4);
  return $serial . $checksum;
}

function verify_key($key)
{
  $serial = substr($key, 0, 40);
  $checksum = substr($key, -4);
  return md5($serial, 0, 4) == $checksum;
}

This is a very simple example, but it is simply instructional.

Essentially you would validate whether the license key is valid on the host's server instead of pinging a script on your server.

The drawback of this is that anyone would be able to generate a valid key by opening the source code and finding validate_key.

You could have it call an external script to do the verify_key, but is it really worth the effort? Also, you will be sacrificing page load time to verify the key.

I recall vBulletin having a very easy to crack licensing system, but they had a hidden 1x1 image in a few sections which pinged a script on their domain. Using the logs, they were able to determine which domains were hosting illegal copies of their software and they simply sent a lawyer's letter to the admin.

If you wanted a more robust solution, I would suggest maybe looking into Zend Guard, but you seem not to care about people cracking your software so personally I would just go as simple as possible.

1 Comment

Yeah there is really not much use developing a complex encryption system when the code is open source...If this was compiled language is a different story. I just need something simple so whoever uses this software does not just tell his friend here you go, use it...Because my plan is to match their email to the key and have a toggle on the server side so even if they passed the same email/key to their friend, it will toggle off his friends plugin and he would be piss and learn never to let his friend use it like that...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.