Created
January 19, 2021 10:14
-
-
Save thinkverse/c8872a7f717b28aa849d672934e0b8d9 to your computer and use it in GitHub Desktop.
Useful snippet for generating quick random passwords
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 | |
$keyspace = '123456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ'; | |
$keyspaceLength = mb_strlen($keyspace, 'utf-8') - 1; | |
$numberOfPasswords = 8; | |
$numberOfChars = 16; | |
$passwords = []; | |
for ($y = 0; $y < $numberOfPasswords; $y++) | |
{ | |
$password = ''; | |
for ($i = 0; $i < $numberOfChars; $i++) | |
{ | |
$password .= $keyspace[random_int(0, $keyspaceLength)]; | |
} | |
array_push($passwords, $password); | |
} | |
var_dump($passwords); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment