Page 1 of 1

How to create a random password using php

Posted: Fri Jul 15, 2011 6:34 pm
by Saman
Nice little function that will generate a completely random password.

Code: Select all

<?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"; 
    srand((double)microtime()*1000000); 
    $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"; 
 
?>

Re: How to create a random password using php

Posted: Sun Dec 25, 2011 11:54 am
by Shalom
Superb work bro.... :biggrin: :biggrin:

Re: How to create a random password using php

Posted: Fri Jan 06, 2012 6:15 pm
by Saman
Another version of a php password generator Another powerful password generator using php.