note 92711 added to function.mt-rand
| From: | Anonymous at osu1 dot php dot net | Date: | Tue, 04 Aug 2009 22:45:31 +0000 |
| Subject: | note 92711 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-159118@lists.php.net to get a copy of this message | ||
Just another random password generator. Assembles passwords such as these:
N_v85kA2_s
8k4jz94_H0
30824n6VcN
useful for... whatever. ;)
$underscores holds the maximum allowed number of underscores. Default is two. The function is
programmed to not add an underscore at the beginning or end of the password, right after another
underscore, or if the maximum # has already been used.
$length holds the length you want the password to be. Default is 10 characters long.
<?php
function alphanumericPass()
{
// Do not modify anything below here
$underscores = 2; // Maximum number of underscores allowed in password
$length = 10; // Length of password
$p ="";
for ($i=0;$i<$length;$i++)
{
$c = mt_rand(1,7);
switch ($c)
{
case ($c<=2):
// Add a number
$p .= mt_rand(0,9);
break;
case ($c<=4):
// Add an uppercase letter
$p .= chr(mt_rand(65,90));
break;
case ($c<=6):
// Add a lowercase letter
$p .= chr(mt_rand(97,122));
break;
case 7:
$len = strlen($p);
if ($underscores>0&&$len>0&&$len<9&&$p[$len-1]!="_")
{
$p .= "_";
$underscores--;
}
else
{
$i--;
continue;
}
break;
}
}
return $p;
}
?>
----
Server IP: 64.71.164.2
Probable Submitter: 69.142.233.248
----
Manual Page -- http://www.php.net/manual/en/function.mt-rand.php
Edit -- https://master.php.net/note/edit/92711
Del: integrated -- https://master.php.net/note/delete/92711/integrated
Del: useless -- https://master.php.net/note/delete/92711/useless
Del: bad code -- https://master.php.net/note/delete/92711/bad+code
Del: spam -- https://master.php.net/note/delete/92711/spam
Del: non-english -- https://master.php.net/note/delete/92711/non-english
Del: in docs -- https://master.php.net/note/delete/92711/in+docs
Del: other reasons-- https://master.php.net/note/delete/92711
Reject -- https://master.php.net/note/reject/92711
Search -- https://master.php.net/manage/user-notes.php