Jump to content

Creating Registration Keys


mschrank99

Recommended Posts

I would like to create license/registration keys for my online application. I have never done this before so I do not know where to start.

 

I suppose I would like a randomly generated string that could be compared to a static value and then a TRUE or FALSE could be returned. I do not know how to do this though. Of course, it gets tricky because I'd need more than just a 1:1 correspondence (like if I used md5()). I'd need several different strings (thousands even) adding up to the same value somehow.

 

How is this possible? How does Microsoft and all the other non-free software vendors create their CD keys and make sure they are valid?

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/38681-creating-registration-keys/
Share on other sites

How other commercial products create their serial keys is a secret as if you knew how to you would be able to make key generators and valid keys yourself (some reverse engineer it and find out anyways though) unless it is validated by a server somewhere.

 

You can make your algorithm anyway you want. Basically you should take some values and pass them into a function that would create the key from them. It should also result in the same key each time the same values are passed to the function. You could do it like this:

<?php
function generate_key($name, $email)
{
$var = sha1($name).sha1($email);

$key = substr($var,strlen($name)+strlen($email), 10);
$key .= "-".substr($var,strlen($name)+22, 10);
$key .= "-".substr($var,strlen($name)-17, 10);
$key .= "-".substr($var,strlen($name)+5, 10);
$key = strtoupper($key);

return $key;
}

echo generate_key("John Doe", "[email protected]"); // outputs: 904FAD297B-31E9CF6362-CB35071C5-B460503904
?>

If your users use unique usernames you can do....

<?php

  $usr = 'username';
  $keywords = array('secretword_one', 'secretword_two', 'secretword_three');
  $key = '';
  
    foreach($keywords as $licensekey) {
    
    $key[] = md5($usr).md5($licensekey);	
    }
  
?>

 

That will create an array $key, with three unique strings/hashes tied to their particular username, and your secret words. You can then easily compare this to see if it validates.

 

Long day so I hope that makes sense...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.