Home Apache PHP Ubuntu MySQL Linux HTML Win CSS Perl Javascript Rants Retro
 
Print This Page
Date Posted: Thursday 04th of February 2010 | Category: PHP
Create a random password using PHP
Create a password in PHP with numbers and letters
This function creates a random password using PHP.

<?php
function createPassword($length) {
$chars = "234567890abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
$i = 0;
$password = "";
while ($i <= $length) {
$password .= $chars{mt_rand(0,strlen($chars))};
$i++;
}
return $password;
}

$password = createPassword(8);
echo "Your 8 character password is: $password";
?>
Related Links:
- Visit totallyPHP to download other great PHP Scripts