Generate Random password using PHP

Generate Random password using PHP

Generating random password using php is helpful for generate default password for the user. it's make secure for the user authentication 

Source

function randomPassword() {

    $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";

    $pass = array(); //remember to declare $pass as an array

    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache

    for ($i = 0; $i < 8; $i++) {

        $n = rand(0, $alphaLength);

        $pass[] = $alphabet[$n];

    }

    return implode($pass); //convert array into a string

}

echo randomPassword();

0 Comments

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed

>