
03-04-10, 11:45 AM
|
|
New Member
|
|
Join Date: Mar 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
|
Create a random password
Hello everyone,
I have the code below that will create a random password for me. I have the codelenght variable set to 10 which creates a random password with 10 characters maximum. The only problem is that sometimes it will create a password with less than 10 characters. How do i edit this so it will always create a random password of exactly 10 characters?
Thanks so much for any help you can provide. I have been at this for a while and don't know where to go from here!
<?
$codelenght = 10;
while($newcode_length < $codelenght) {
$x=1;
$y=3;
$part = rand($x,$y);
if($part==1){$a=48;$b=57;} // Numbers
$code_part=chr(rand($a,$b));
$newcode_length = $newcode_length + 1;
$newcode = $newcode.$code_part;
}
?>
|

03-04-10, 05:27 PM
|
|
Aspiring Coder
|
|
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
|
|
Not my function, although I did add some functionality to it. But, it works, and will return a totally random password, and you can set the length.
|

03-04-10, 08:01 PM
|
 |
Community Liaison
|
|
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
|
|
__________________
The toxic ZCE
|

03-04-10, 08:32 PM
|
 |
-
|
|
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
|
|
|
|

03-05-10, 09:20 PM
|
 |
Community Liaison
|
|
Join Date: Feb 2004
Posts: 1,232
Thanks: 1
Thanked 11 Times in 11 Posts
|
|
Quote:
Originally Posted by wirehopper
|
Have you read that link you'd provided? shuffle() returns boolean, it's argument is passed as a reference.
And $chars is an array... substr() accepts a string as it's first argument. 
__________________
The toxic ZCE
|

03-05-10, 10:08 PM
|
 |
-
|
|
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
|
|
Ooops.
General idea was to use a library function instead of a loop.
I stand corrected.
Should be
PHP: str_shuffle - Manual
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|