Skip to content

Instantly share code, notes, and snippets.

@thinkverse
Created January 19, 2021 10:14
Show Gist options
  • Save thinkverse/c8872a7f717b28aa849d672934e0b8d9 to your computer and use it in GitHub Desktop.
Save thinkverse/c8872a7f717b28aa849d672934e0b8d9 to your computer and use it in GitHub Desktop.
Useful snippet for generating quick random passwords
<?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