note 57409 deleted from function.mt-rand by cmb
| From: | cmb@php.net | Date: | Sun, 31 Mar 2019 08:33:58 +0000 |
| Subject: | note 57409 deleted from function.mt-rand by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210456@lists.php.net to get a copy of this message | ||
Note Submitter: frans-jan at van-steenbeek dot net
----
My try at generating a reasonably secure password:
<?php
function keygen() {
$tempstring =
"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNO
PQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABC
DEFGHIJKLMNOPQRSTUVWXYZ!?@#$%&*[]{}();:,<>~+=-_
/|\\";
for($length = 0; $length < mt_rand(10, 15); $length++) {
$temp = str_shuffle($tempstring);
$char = mt_rand(0, strlen($temp));
$pass .= $temp[$char];
}
return $pass;
}
echo(keygen());
echo("\n");
?>
This generates a password of an undefined length (in this case, 10 to 15 chars) consisting of
numbers, UPPERCASE letters lowercase letters and a set of signs. I have doubled the chance of number
and letters to reduce the confusion with my users.