Re: Regular Expression Help: genreate alphanumeric, 8 chars

From: Date: Thu, 27 Nov 2003 13:04:54 +0000
Subject: Re: Regular Expression Help: genreate alphanumeric, 8 chars
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-171199@lists.php.net to get a copy of this message
...as in... <? // Could've been done with ASCII sets, but this way // you can easily tweak the eligible characters. $eligible='abcdefghijklmnopqrstuvwxyz0123456789'; $pwdLen=8; $password=''; for($i=0;$i<$pwdLen;$i++) {
    $password.=$eligible[rand(0,strlen($eligible))];
} echo("Your new password: $password\n"); ?> Bogdan David T-G wrote:
Shaun -- [No need to post twice...] ...and then Shaun said... % % Hi, Hi! % % I need to generate a lowercase alphanumeric passwrord thats 8 characters % long, has anyone got a function that can do this? This isn't really a regular expression question, since you'd use an expression to check if a string matched your requirements but not to generate such a string. A function should be easy: just loop 8 times over spitting out a random char between a and z or 0 and 9 (use rand() to generate a number between 0 and 35 and then map that to the char). % % Thanks for your help Enjoy :-) HTH & HAND :-D


« previous php.general (#171199) next »