Password generator function - simple

10.06.2017 | PHP

 
function random_password( $length = 8 ) {

    $chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-=+;:,.?";

    $password = '';

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

                $password .= $chars[mt_rand(0, strlen($chars) – 1)];

                }

    return $password;

                }

               

$password = random_password(9);