Re: Password generator
| From: | Davy Obdam | Date: | Tue, 17 Jun 2003 10:45:47 +0000 |
| Subject: | Re: Password generator | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-20375@lists.php.net to get a copy of this message | ||
Thanks for you reactions people, i have found the solution
Best regards,
Davy Obdam
Met vriendelijke groeten uit Den Haag;-)
Daniel Beulshausen wrote:
At 11:45 17.06.2003 +0200, Davy Obdam wrote:-- ----------------------------------------------------------------------- Davy Obdam Web application developer Networking4all email: d.obdam@networking4all.com email: info@davyobdam.com internet: http://www.networking4all.com -----------------------------------------------------------------------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