mschrank99 Posted February 15, 2007 Share Posted February 15, 2007 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! Quote Link to comment https://forums.phpfreaks.com/topic/38681-creating-registration-keys/ Share on other sites More sharing options...
Daniel0 Posted February 15, 2007 Share Posted February 15, 2007 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/38681-creating-registration-keys/#findComment-185792 Share on other sites More sharing options...
Caesar Posted February 15, 2007 Share Posted February 15, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/38681-creating-registration-keys/#findComment-185794 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.