PHPBuilder - Create Random Password



RSS Twitter
Snippets Algorithms

Create Random Password

by: Tito
|
December 28, 2009

Version: 1.0

Type: Function

Category: Algorithms

License: GNU General Public License

Description: Very simple small code to generate random password.



<?php

/**
 * The letter l (lowercase L) and the number 1
 * have been removed, as they can be mistaken
 * for each other.
 * Tito code :eyeswideshut25@hotmail.com
 */

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";

?> 

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Tito

Comment:



Comment:

(Maximum characters: 1200). You have characters left.