Page 1 of 1

limiting confirmation code

Posted: Mon Oct 12, 2009 10:53 am
by adsegzy
Hello My Success-Oriented Friends,

Is it possible to limit the generated confirmation code to a specific limit, that is may be to general a 20 digits confirmation code.

Regards,
adsegzy

Re: limiting confirmation code

Posted: Mon Oct 12, 2009 11:11 am
by Weiry
I really hate to ask this... but,

What generated confirmation code?
No code? No reference? No hint?

Im sure when i did a php.net search for a confirmation function it didnt return one :?

Re: limiting confirmation code

Posted: Mon Oct 12, 2009 12:50 pm
by adsegzy
Hello Weiry,

Is it that you dont know how to generate confirmation code? let me know so that i can post the code for genenrating confirmation code.

Re: limiting confirmation code

Posted: Mon Oct 12, 2009 1:01 pm
by superdezign
Create a whitelist of characters that can be in the confirmation code, and randomly add them to the code.

Code: Select all

function generateConfirmationCode($length = 30) {
  $whitelist = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  $confirmationCode = "";
 
  for ($i = 0; $i < $length; $i++) {
    $confirmationCode .= $whitelist[rand(0, strlen($whitelist) - 1)];
  }
}

Re: limiting confirmation code

Posted: Mon Oct 12, 2009 8:28 pm
by Weiry
adsegzy wrote:s it possible to limit the generated confirmation code to a specific limit,
If you state your questions more carefully, i can answer better. You ask is it possible, but you make no reference to that you are actually asking for a confirmation code script. So if you were using a script you already had, i wouldnt know, but if you made one yourself, then yes it is possible.

superdezign posted one way of doing it, and here is mine:

Code: Select all

    function getConfirmation($length){
        $returnArray = array();
        for($i = 0; $i<$length; $i++){
            array_push($returnArray,chr(mt_rand(63,126)));
        }
        return implode($returnArray);
    }
    print getConfirmation(20);
With this you don't need to manually set the characters your confirmation code uses. This is calculated from chr().
Normally i would set the mt_rand() between 33,126 but i was experiencing a problem with a few of the symbol ascii characters.

Re: limiting confirmation code

Posted: Mon Oct 12, 2009 9:51 pm
by Mirge
Another way to do it: http://us2.php.net/uniqid/

I've used this a few times :)