Friday, 5 June 2015

PHP: Create a random password

<?php

/** * The letter l (lowercase L) and the number 1

* have been removed, as they can be mistaken

* for each other. */

function createRandomPassword(){   

$chars = "abcdefghijkmnopqrstuvwxyz023456789";   
$i = 0;   
$pass = '' ; 
while ($i <= 7) {
$num = rand() % 33;     
$tmp = substr($chars, $num, 1);     
$pass = $pass . $tmp;       
$i++;   

return $pass;
}

// Usage$password = createRandomPassword();
echo "Your random password is: $password";
?>

0 comments:

Post a Comment