note 42781 added to function.rand
| From: | bob at rawkstar dot net | Date: | Sat, 29 May 2004 00:49:51 +0000 |
| Subject: | note 42781 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70262@lists.php.net to get a copy of this message | ||
Yet another random password generator, but this one creates readable/pronounceable passwords...
<?php
function randompass()
{
$rand_pass = ''; // makes sure the $pass var is empty.
for( $j = 0; $j < 3; $j++ )
{
$startnend = array(
'b','c','d','f','g','h','j','k','l','m','n',
'p','q','r','s','t','v','w','x','y','z',
);
$mid = array(
'a','e','i','o','u','y',
);
$count1 = count( $startnend ) - 1;
$count2 = count( $mid ) - 1;
for( $i = 0; $i < 3; $i++)
{
if( $i != 1 )
{
$rand_pass .= $startnend[rand( 0, $count1 )];
}
else
{
$rand_pass .= $mid[rand( 0, $count2 )];
}
}
}
return $rand_pass;
}
$rand_pass = randompass();
echo '<p>pass: <strong>' . $rand_pass . '</strong></p>';
echo '<p>md5: <strong>' . md5( $rand_pass ) .
'</strong></p>';
?>
Some examples are:-
pohyerdib
kibkudjam
fizvoszeb
jyshevram
Easy to remember (since it's basically 3, 3 letter words)
I've put a y in the list of vowels since it works well as a middle letter in the 3 letter
words.
This is excellent for a random password generator for a 'forgot password' type function.
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42781
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42781&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42781&report=yes
Search -- http://master.php.net/manage/user-notes.php