• 0

Windows License Key Copy (PHP)


Question

I am looking for a Similar type of encryption to what Windows uses for their license keys. and from what i've developed, it can be hacked pretty easily.

<?PHP
function randLetter()
{
    $int = rand(0,26);
    $a_z = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $rand_letter = $a_z[$int];
    return $rand_letter;
}
function license() {
$license .= rand(0,9);
$license .=  randLetter();
$license .= rand(0,9);
$license .=  randLetter();
$license .= rand(0,9);
$license .= "-";
$license .=  randLetter();
$license .=  randLetter();
$license .= rand(0,9);
$license .=  randLetter();
$license .= rand(0,9);
$license .= "-";
$license .= rand(0,9);
$license .=  randLetter();
$license .= rand(10,99);
$license .=  randLetter();
$license .= "-";
$license .=  randLetter();
$license .=  randLetter();
$license .= rand(100,999);
return $license;
}
license();
?>

Could anyone suggest a much easier and simple way compared to this?

Link to comment
Share on other sites

12 answers to this question

Recommended Posts

  • 0

Its for a Licensing module. EG/ User signs up, it gives them the license key.

And i don't want to use encryption because it won't contain any data. will only be useless random letters.

Link to comment
Share on other sites

  • 0

also, Sha1 is for losers. Lrn2Sha512

To be perfectly frank, if you actually needed anything close to SHA-512 encryption, you would not be on a forum asking how to write a simple encryption algorithm. :sleep2:

Bigger hashes are significantly slower to encode and take up more space to store. Your own license() function returns a value that is shorter than even an MD5 hash, let alone the current go-to standard of SHA-1.

If you need to store some data with the key, simply give the hash a prefix or suffix with that data. Much like credit card companies give special significance to the first few digits of the numbers they issue.

Link to comment
Share on other sites

  • 0
function get_license($seed = null){
	$hash = sha1(
 	sprintf(
 	'%s-%s',
 	null === $seed ? str_shuffle(implode('', range('a', 'z'))) : $seed,
 	microtime(false)
 	)
	);
	return sprintf(
 	'%s-%s-%s-%s-%s-%s',
 	substr($hash, 0, 5),
 	substr($hash, 5, 5),
 	substr($hash, 10, 5),
 	substr($hash, 15, 5),
 	substr($hash, 20, 5),
 	substr($hash, 25, 5)
	);
}

Link to comment
Share on other sites

  • 0

LOL, move this thread to the joke section. Windows uses a complex public-key encryption system for product keys. This guy wants something similar that can't be easily hacked?

Link to comment
Share on other sites

  • 0

It's not as simple as just generating random numbers. There's an algorithm used so that keys can be checked if they're in the valid format before they're sent to the server for activation. I'm actually kinda curious myself but I haven't bothered searching the net for anything.

Link to comment
Share on other sites

  • 0

LOL, move this thread to the joke section. Windows uses a complex public-key encryption system for product keys. This guy wants something similar that can't be easily hacked?

I want it so i can hack it from the main server, so on demand i can find out if its a legit license or not.

It's not as simple as just generating random numbers. There's an algorithm used so that keys can be checked if they're in the valid format before they're sent to the server for activation. I'm actually kinda curious myself but I haven't bothered searching the net for anything.

Its stored in my site DB, and then again in the user's CMS download. So it would require to verify it.

Link to comment
Share on other sites

  • 0

Just a quick way to make it more random would be to let each character be chosen from the full spectrum of 0-9 AND A-Z.

Remember though that if you just use random keys without some sort of sequential method for generating them, you'll have to check for duplicates every time you generate a new one.

Link to comment
Share on other sites

  • 0

function get_license($seed = null){
	$hash = sha1(
 	sprintf(
 	'%s-%s',
 	null === $seed ? str_shuffle(implode('', range('a', 'z'))) : $seed,
 	microtime(false)
 	)
	);
	return sprintf(
 	'%s-%s-%s-%s-%s-%s',
 	substr($hash, 0, 5),
 	substr($hash, 5, 5),
 	substr($hash, 10, 5),
 	substr($hash, 15, 5),
 	substr($hash, 20, 5),
 	substr($hash, 25, 5)
	);
}

Thank you, worked greatly (Just applied variable to the sprintf then applied strtoupper() to it)

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.