View Single Post
Old 11-03-2007, 11:36 AM   · #1
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 
Name: Eric
Location: Kentucky
Trader Rating: (140)
Join Date: Mar 2005
Posts: 4,196
NP$: 1662.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
Random Passwords

Got a tad bored today, so wrote a function for random passwords. Maybe it will help someone.

PHP Code:
<?php

/**
* Generate a random password.
*
* @param  integer  $numchars      How long do we need the password to be?
* @param  boolean  $specialchars  Include the special characters?
* @param  boolean  $extrashuffle  Include an extra randomization on the password string?
* @return string
*/
function random_pass($numchars = 8, $specialchars = true, $extrashuffle = false)
{
    
$numchars = intval($numchars);
    
$numchars = ($numchars > 16 OR $numchars < 8) ? 8 : $numchars;

    
$chars = array_merge(range('a', 'z'), range(0, 9));

    if (
$specialchars)
    {
        
$chars = array_merge($chars, array('!', '$', '_', '-', '#', '@'));
    }
    
shuffle($chars);

    
$pass = '';

    for (
$i = 0; $i <= $numchars; $i++)
    {
        
$pass .= $chars[$i];
    }

    if (
$extrashuffle)
    {
        return
str_shuffle($pass);
    }
    return
$pass;
}

// Example, returns: 3ck#4sib2
echo random_pass(8, true, true);

?>


Please register or log-in into NamePros to hide ads
__________________

SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.1 now available!!
MetaCreator.com - Free Meta Tag Creator
CodingPlanet.com - Coming soon...
SecondVersion is offline   Reply With Quote
Site Sponsors
Hunting Moon Special Offer Hunting Moon
Advertise your business at NamePros
All times are GMT -7. The time now is 03:19 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.