Re: Password generator

From: Date: Tue, 17 Jun 2003 10:39:38 +0000
Subject: Re: Password generator
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-20373@lists.php.net to get a copy of this message
At 11:45 17.06.2003 +0200, Davy Obdam wrote:
Hi people, I have to make a password generator, but i have a little problem. - It needs to generate password 8 characters long, and including 1 or 2 special characters(like #$%&*@). - Those special characters can never appear as the first or last character in the string... anywhere between is fine. I have a password generator script now that does the first thing... but the special character can be in front or back of the string wich it shouldnt.. i have been looking on the web for this but i havent found the answer. Below is my scripts so far.. Any help is appreciated, thanks for your time,
please don't cross-post.
<?php
function generatePassword( $length = 8 ) {
        $alphaNumChar = array( 'a','b','c','d','e','f','g','h','e','f','g','h','i','j','k',
        'l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6',
        '7','8','9' );
        $specialChar = array( '%','#','*','&' );
        $allChars = array_merge( $alphaNumChar, $specialChar );
        $returnValue = '';
        mt_srand( lcg_value() * 10000 + time() );
        $returnValue .= $alphaNumChar[ array_rand( $alphaNumChar ) ];
        if( ( $length -= 2 ) > 0 ) {
                while( $length-- > 0 ) {
                        $returnValue .= $allChars[ array_rand( $allChars ) ];
                }
        }
        $returnValue .= $alphaNumChar[ array_rand( $alphaNumChar ) ];
        return $returnValue;
} echo generatePassword(); ?> <<< mit freundlichen grüßen aus berlin, daniel /*-- Daniel Beulshausen - daniel@php4win.com Using PHP on Windows? http://www.php4win.com

« previous php.windows (#20373) next »