Reputation: 31
I am trying to generate some sort of serial number using a customer name. This is for a PHP software I am developing. But I have never done trial systems and serial generation and stuff like this.
This is the code I use to generate the serial numbers:
<?php
// URL is = http://teionsoft.com/classified/keygen.php?token=
$token = @$_POST['token'];
if(empty($token))
{
echo '
<p>Token can not be blank or zero.</p>
<p>
<form action="keygen.php" method="post">
<input type="text" name="token" id="token" placeholder="Type in your full name" /><br /><br />
<input type="submit" name="submit" value="Get serial!" />
</form>
</p>';
exit;
}
function serialKey() {
// Create a token
// GUID is 128-bit hex
$hash = strtoupper(md5($token));
// Create formatted GUID
$guid = '';
// GUID format is XXXXX-XXXXX-XXXXX-XXXXX-XXXXX for readability
$guid .= substr($hash, 0, 5) .
'-' .
substr($hash, 8, 5) .
'-' .
substr($hash, 12, 5) .
'-' .
substr($hash, 16, 5) .
'-' .
substr($hash, 20, 5);
// temporary code to test base64 codeing / decoding ;
$string = $guid;
$encoded = base64_encode($string);
$decoded = base64_decode($encoded);
echo $encoded ."<br /><br />";
echo $decoded;
}
if(isset($_POST['submit']))
{
serialKey();
}
?>
How can I extract the customer name from the serial number?
Upvotes: 0
Views: 144
Reputation: 30927
The fact that you have $hash = strtoupper(md5($token))
should be a clue that this is an irreversible transform. You'll need to store the original if you want to use the hash as a lookup key.
Upvotes: 1
Reputation:
If i understand your question correctly, you need to generate a serial number based on the customer name, and later be able to decode the serial number to get the customer name.
You could convert the name to hex, but the string would in most cases get longer than the XXXXX-XXXXX-XXXXX-XXXXX-XXXXX format you're using now.
Wouldn't it be better to just save the serial number in the database so you just have to check if the serial number is in the same row as the customer name?
Upvotes: 1