ARTLUNG LAB Share

January 3, 2009

20 Random Alphanumeric Passwords

The passwords:

No record is made of these passwords.


arMKfKAWE6QEzQJWUNuN
Vxyp93BVPDvuZBtPH37u
tcM8D7TDujNLMxXUKnBG
NXgktDxMS9RufRcPoUHc
CNWfTNYmWWAwByDFgM8d
p2ZDVjAo3Rm7eYch7sra
fvkn6cLWt9ACcDEWAKzH
ZguSftjwvQLfFANgWTT9
dqQgSZjc2YJacdzojugG
awsRVpMzDQUxnwBLRNSb
sxbbzHDFJbKf6VBLovRJ
DmxYdV7czzYZzoeHwotU
urBdm9BpAB4BcwDcjfQQ
QmHT47zxbP9okwukgPxL
KGB4nzhHtqpB4TWQJHta
9QTFTfB6n62MCL8efBSB
gWvxtfL7EvrxfQpTExkR
hYscMA8AkC2UDgpBjWS3
JU7S3XzxhD7nytc6EqHt
kFjuhHuqAYkFP2zFMcxZ

The code for the class


<?php

/**
 * Class PasswordGenerator
 *
 * @category PHP
 * @package  Classes
 * @author   Joe Crawford <joe@artlung.com>
 * @license  GPL 2.0+ - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * @version  Release: 1.0
 * @link     https://artlung.com/
 * @since    2024-12-03
 */
class PasswordGenerator
{

    public static 
$letters "2346789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnopqrstuvwxyz";
    public static 
$length "20";
    public 
$letters_array;

    
/**
     * PasswordGenerator constructor.
     */
    
function __construct()
    {
        
$this->letters_array = array();

        for (
$a 0$a strlen(self::$letters); $a++) {
            
$this->letters_array[] = self::$letters[$a];
        }
    }


    
/**
     * Make password
     *
     * @return string
     */
    
function make(): string
    
{
        
$password '';
        for (
$i 0$i self::$length$i++) {
            
srand((float)microtime() * 10000000);
            
$password .= $this->letters_array[array_rand($this->letters_array)];
        }
        return 
$password;

    }

    
/**
     * Print one password
     *
     * @return void
     */
    
function printOne()
    {
        print 
$this->make();
    }

    
/**
     * Print many passwords
     *
     * @param $num
     *
     * @return void
     */
    
function printMany($num)
    {
        for (
$i 0$i $num$i++) {
            
$this->printOne();
            print 
"\n";
        }
    }


}

How to invoke the class

$PG = new PasswordGenerator();
$PG->printMany(20);