Post: PHP License Generator
04-16-2016, 07:36 PM #1
(adsbygoogle = window.adsbygoogle || []).push({}); This is something simple and not hard to do. If you are going to use Licenses remember to check for
collisions. You don't want people having the same license. Though this hardly ever occurs.

Also, I made this a class so people can add on to it easily.
Some examples:
Methods: isBanned, getPSN (Last PSN Logged into it), and etc.

If you are going to add to it I recommend making the generateLicense method a static and returning
a License class. Also, making the license class __construct method have a license code argument.

    
<?php

class License {

/**
* Max length of the license. Must be divisible by 5.
* @var int
*/
private $_licenseLength = 25;

public function __construct() { }

/**
* Generates a license key.
*
* @return string
*/
public function generateLicense() {

$license = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$charlen = strlen($chars);

if ($this->_licenseLength % 5 != 0)
$this->_licenseLength = 25;

for ($i = 0; $i < $this->_licenseLength; $i++) {
$key = mt_rand(0, $charlen);

if ($key > 0)
$key--;

$license .= $chars[$key];
}
$license = chunk_split($license, 5, '-'Winky Winky;
$license = substr($license, 0, -1);

return $license;
}
}


How to use:
    
<?php
// This will display the license key.
// Make sure to include the file that contains the class.
$licenseClass = new License();
echo $licenseClass->generateLicense() . "\n";
?>
04-19-2016, 09:47 PM #2
Jelly
Maggbot timeout!
.....
Last edited by Jelly ; 04-20-2016 at 07:02 AM.
04-19-2016, 10:45 PM #3
Originally posted by Jelly View Post
Idk if I'm right but why not make the code shorter and easier
strtoupper(substr(str_shuffle(MD5(microtime())), 0, 12));

something like this I mean of course you can do better and probably shorter but being on my phone it's a bit hard and well that's all I can think of right now


cos his making a key like 1111-1111-1111 m8ty

The following user thanked lachie444 for this useful post:

Jelly
04-20-2016, 12:50 AM #4
Mine is 25 characters to allow more keys to be generated, and not max out.

Yours uses MD5 and MD5 sometimes generates the same hash (rare).

I try to use pseudo-random for the keys.

In addition yours is time that is md5'd which can easily be guessed if you know the time of purchase. (time of purchase can be found out quite easily)

I also try to make the code readable.

There are still a quite of few more reasons that I have not named.

The following user thanked D4tabase for this useful post:

Jelly
04-20-2016, 07:02 AM #5
Jelly
Maggbot timeout!
Originally posted by D4tabase View Post
Mine is 25 characters to allow more keys to be generated, and not max out.

Yours uses MD5 and MD5 sometimes generates the same hash (rare).

I try to use pseudo-random for the keys.

In addition yours is time that is md5'd which can easily be guessed if you know the time of purchase. (time of purchase can be found out quite easily)

I also try to make the code readable.

There are still a quite of few more reasons that I have not named.


I see

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo