Last active
October 15, 2019 11:05
-
-
Save fantasyczl/dd46cf5e38bde62a95bceb7accaf2692 to your computer and use it in GitHub Desktop.
生成随机密码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Generate Password | |
*/ | |
function generate_password($len) | |
{ | |
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890~!@#$%^&*.?"; | |
$max = strlen($chars) - 1; | |
$pw = ''; | |
for ($i = 0; $i < $len; $i++) { | |
$r = random_int(0, $max); | |
$pw .= $chars[$r]; | |
} | |
return $pw; | |
} | |
if (!empty($argv[1])) { | |
$len = $argv[1]; | |
} else { | |
$len = 20; | |
} | |
$pw = generate_password($len); | |
echo "password: $pw" . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment