Generate random password php function

function randomPass() {
    // How long should it be?
    $length = 10;
    $characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ";
    $string = "";    

    for ($p = 0; $p < $length; $p++) {
        $string .= $characters[mt_rand(0, strlen($characters))];
    }
    return $string;
}
Author: michael schouman on October 10, 2011
Category: Code snippets

Leave a Reply

Last articles