Tuesday, October 4
Shadow

Generate random password

<?php

/**
* Generate a random password
* @param int $length
*/

function random_password ($length = 8, $chars = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789") 
{

    $pw = [];
    $l = strlen($chars) - 1;

    for ($i = 0; $i < $length; $i++):

        $n = rand(0, $l);
        $pw[] = $chars[$n];

    endfor;

    return implode($pw);

}

Leave a Reply