Categories

Category Specific RSS

Password generator

<?php
 
function wd_generatePassword($length=8, $possible=’$=@#23456789bcdfghjkmnpqrstvwxyz’)
{
    $password = ”;
 
    $possible_length = strlen($possible) – 1;
 
    #
    # add random characters to $password for $length
    #
 
    while ($length–)
    {
        #
        # pick a random character from the possible ones
        #
 
        $except = substr($password, -$possible_length / 2);
 
        for ($n = 0 ; $n < 5 ; $n++)
        {
            $char = $possible{mt_rand(0, $possible_length)};
 
            #
            # we don’t want this character if it’s already in the password
            # unless it’s far enough (half of our possible length).
            # note: we have 4 tries to find a suitable one.
            #
 
            if (strpos($except, $char) === false)
            {
                break;
            }
        }
 
        $password .= $char;
    }
 
    return $password;
}
?>

FacebookTwitterGoogle+PinterestTumblrStumbleUponRedditLinkedInBaiduApp.netBufferDeliciousDiggDiigoWordPressBlogger PostEmailPrintFriendlyShare

Leave a Reply