Comparto esta funcion para generar claves aleatorias. Es facil de usar y de entender.

 

<?php

 

function generatePassword( $length=9, $strength=4 ) {

    $vowels = ‘aeiou’;

    $consonants = ‘bcdfghjklmnpqrstvwxyz’;

    if ($strength & 1) {

        $consonants .= ‘BCDFGHJKLMNPQRSTVWXYZ’;

    }

    if ($strength & 2) {

        $vowels .= "AEIOU";

    }

  [...]