Re: [PHP] Generating PINs
Usually software uses a specific serial number format, rather than a remote database of valid numbers. for instance, the fifth character must be the third % tenth. Something like that. 3HH5R could be random, and E59VB and 7SX99 would be determined by a complex algorithm operating on the five characters. This is why when you enter an incorrect key, it can easily be recognized- and why keygens work ;) On Monday 13 May 2002 21:13 pm, Alvin Tan wrote: Hi All, This is not really a PHP question, but seeing that the final application will be in PHP, I figured this'll be the best place to start. I have a client who wants to release a unique PIN for each product they sell which works as a key to get more goodies on the website. How/where can I get a large number of PINs, much like a software key (e.g. 3HH5R-E59VB-7SX99 or similar)? TIA lvin -- There is no pain so great as the memory of joy in present grief. Aeschylus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generating PINs
On Tue, 14 May 2002, Alvin Tan wrote: This is not really a PHP question, but seeing that the final application will be in PHP, I figured this'll be the best place to start. I have a client who wants to release a unique PIN for each product they sell which works as a key to get more goodies on the website. How/where can I get a large number of PINs, much like a software key (e.g. 3HH5R-E59VB-7SX99 or similar)? The easiest is probably something like this... Generating PINs: $randnum = strval(rand(1000, )); $secretword = 'purple%chicken^'; $hash = md5($randnum . $secretword); $PIN = substr($randnum, 0, 4) . substr($hash, 0, 2) . '-' . substr($hash, 2, 6) . '-' . substr($hash, 8, 2) . substr($randnum, 4); This will generate PINs in a format like 8087a5-6b09eb-a65859. Verifying PINs: $PIN = str_replace('-', '', $PIN); $secretword = 'purple%chicken^'; $randnum = substr($PIN, 0, 4) . substr($PIN, 14, 4); $hash = substr($PIN, 4, 10); if (substr(md5($randnum . $secretword), 0, 10) == $hash) print PIN is valid; else print PIN invalid; As long as you can keep the secret word ($secretword) confidential, this will let you generate an infinite supply (okay, several million anyway) of PINs that can be validated with the simple code above, yet which are very difficult to fake. Obviously, if you need to locate the validation code on someone else's machine, this is not a good approach. And, like most things, it is susceptible to brute-force attacks unless you put in something to throttle repeated attempts at guessing PINs. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generating PINs
Hi, Thanks to everyone for help on this matter. Combined with some SQL insert statements and loops, it works great. Now to get the numbers to a printer... As usual, this list ROCKS lvin At 03:23 PM 5/14/02, Miguel Cruz wrote: On Tue, 14 May 2002, Alvin Tan wrote: This is not really a PHP question, but seeing that the final application will be in PHP, I figured this'll be the best place to start. I have a client who wants to release a unique PIN for each product they sell which works as a key to get more goodies on the website. How/where can I get a large number of PINs, much like a software key (e.g. 3HH5R-E59VB-7SX99 or similar)? The easiest is probably something like this... Generating PINs: $randnum = strval(rand(1000, )); $secretword = 'purple%chicken^'; $hash = md5($randnum . $secretword); $PIN = substr($randnum, 0, 4) . substr($hash, 0, 2) . '-' . substr($hash, 2, 6) . '-' . substr($hash, 8, 2) . substr($randnum, 4); This will generate PINs in a format like 8087a5-6b09eb-a65859. Verifying PINs: $PIN = str_replace('-', '', $PIN); $secretword = 'purple%chicken^'; $randnum = substr($PIN, 0, 4) . substr($PIN, 14, 4); $hash = substr($PIN, 4, 10); if (substr(md5($randnum . $secretword), 0, 10) == $hash) print PIN is valid; else print PIN invalid; As long as you can keep the secret word ($secretword) confidential, this will let you generate an infinite supply (okay, several million anyway) of PINs that can be validated with the simple code above, yet which are very difficult to fake. Obviously, if you need to locate the validation code on someone else's machine, this is not a good approach. And, like most things, it is susceptible to brute-force attacks unless you put in something to throttle repeated attempts at guessing PINs. miguel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Generating PINs
Hi All, This is not really a PHP question, but seeing that the final application will be in PHP, I figured this'll be the best place to start. I have a client who wants to release a unique PIN for each product they sell which works as a key to get more goodies on the website. How/where can I get a large number of PINs, much like a software key (e.g. 3HH5R-E59VB-7SX99 or similar)? TIA lvin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Generating PINs
On Tue, May 14, 2002 at 12:13:08PM +0800, Alvin Tan wrote: I have a client who wants to release a unique PIN for each product they sell which works as a key to get more goodies on the website. How/where can I get a large number of PINs, much like a software key (e.g. 3HH5R-E59VB-7SX99 or similar)? Does md5() fit you needs? http://www.php.net/manual/en/function.md5.php -- Daniel Tryba -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Generating PINs
Well, you could produce those randomly. Store all the PINs to a database and before storing compare that it doesn't exist yet. Here is a piece of code to produce PINs in _exactly_ that format you want. I've done it for myself, but feel free to use it in any way you like: ? srand((double) microtime() * 100); for ($i=0; $i 3; $i++) { // $i 3 tells you how many 'parts' there should be for ($n=0; $n 5; $n++) { // $n 5 tells you how many chars there is in each part $nType = rand(1,3); if ($nType == 1) // A number between 0 - 9 $strChar = rand(0,9); elseif ($nType == 2) { // A small letter between a - z $strChar = chr(rand(65,90)); } elseif ($nType == 3) { // A capital letter between A - Z $strChar = chr(rand(97,122)); }; $strCode .= $strChar; }; // If it ain't the last part, add the separator char if ($i != 2) $strCode .= -; }; ? Niklas -Original Message- From: Alvin Tan [mailto:[EMAIL PROTECTED]] Sent: 14. toukokuuta 2002 7:13 To: [EMAIL PROTECTED] Subject: [PHP] Generating PINs Hi All, This is not really a PHP question, but seeing that the final application will be in PHP, I figured this'll be the best place to start. I have a client who wants to release a unique PIN for each product they sell which works as a key to get more goodies on the website. How/where can I get a large number of PINs, much like a software key (e.g. 3HH5R-E59VB-7SX99 or similar)? TIA @lvin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php