In the API docs, you post the code for generating the md5 license keys.
Can you please post the code for the standard method? I would like to modify it slightly to customize the first block of characters.
Thanks
Posted 12 March 2011 - 09:21 PM
Posted 14 March 2011 - 02:30 PM
Posted 14 March 2011 - 02:58 PM
<?php
function genRandomString($length) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters)-1)];
}
return strtoupper($string);
}
// Generate the code itself. (ABC##-#####-#####-#####)
function generateCode() {
$code = 'ABC';
$code .= genRandomString(2);
$code .= '-';
$code .= genRandomString(5);
$code .= '-';
$code .= genRandomString(5);
$code .= '-';
$code .= genRandomString(5);
return $code;
}
echo generateCode();
?>
Posted 14 March 2011 - 03:45 PM
Posted 14 March 2011 - 04:19 PM
I'll post this for you tomorrow. PM me if I forget
Posted 15 March 2011 - 04:54 AM
<?php
/**
* @file standard.php Generates an Standard License Key (XXXX-XXXX-XXXX-XXXX-XXXX)
*
* $Copyright: $
* $License: $
* $Author: mark $
* $LastChangedDate: 2011-03-11 09:49:17 +0000 (Fri, 11 Mar 2011) $
* $Revision: 8028 $
* @since 30th December 2010
*/
/**
*
* @class licenseKey_standard
* @brief Generates an Standard License Key (XXXX-XXXX-XXXX-XXXX-XXXX)
*
*/
class licenseKey_standard
{
/**
* Number of blocks
*
* @var $blocks
*/
private static $blocks = 5;
/**
* Number of characters in a block
*
* @var $characters
*/
private static $characters = 4;
/**
* Lowest allowed ASCII number
*
* @var $low
*/
private static $low = 48; // 0
/**
* Highest allowed ASCII number
*
* @var $low
*/
private static $high = 90; // Z
/**
* Disallowed ASCII numbers
*
* @var $disallowed
*/
private static $disallowed = array( 58, 59, 60, 61, 62, 63, 64 ); // Various non A-Z / 0-9 characters
/**
* Seperator between blocks
*
* @avr $seperator
*/
private static $seperator = '-';
/**
* Generates a License Key
*
* @param array $member Member Data
* @param array $purchase Purchase Data
* @return @e string License Key
*/
public static function generate( $member, $purchase )
{
$key = array();
foreach ( range( 1, self::$blocks ) as $i )
{
$_k = '';
foreach ( range( 1, self::$characters ) as $j )
{
do
{
$chr = rand( self::$low, self::$high );
}
while ( in_array( $chr, self::$disallowed ) );
$_k .= chr( $chr );
}
$key[] = $_k;
}
return implode( self::$seperator, $key );
}
}
Posted 15 March 2011 - 05:36 AM
0 members, 0 guests, 0 anonymous users