[advanced search]
Next Live Event: NamePros Live Auction, May 23rd at 6PM EDT
Results from the May 8th live auction are here.
13 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 11-03-2007, 11:36 AM   · #1
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 
Name: Eric
Location: Kentucky
Trader Rating: (135)
Join Date: Mar 2005
Posts: 4,046
NP$: 1958.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
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
SecondVersion is offline   Reply With Quote
Old 11-03-2007, 12:31 PM   · #2
Daniel
Danltn.com
 
Daniel's Avatar
 
Name: Daniel Neville
Location: Danltn.com / Nottingham, UK
Trader Rating: (65)
Join Date: May 2007
Posts: 1,162
NP$: 638.56 (Donate)
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
Ethan Allen Fund Ethan Allen Fund
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?
* @param  boolean  $mixedcase     Mixed case or solely lowercase?
* @return string
*/
function random_pass($numchars = 8, $specialchars = true, $extrashuffle = false, $mixedcase = true)
{
    
$numchars = intval($numchars);
    
$numchars = ($numchars > 16 OR $numchars < 8) ? 8 : $numchars;
    
    
$chars = array_merge(range('a', 'z'), range(0, 9));

    if (
$mixedcase) /* Extra case */
    
{
        
$chars = array_merge($chars, range('A','Z'));
    }
    
    if (
$specialchars)
    {
        
$chars = array_merge($chars, array('!', '$', '_', '-', '#', '@'));
    }
    
shuffle($chars);

    
$pass = '';

    for (
$i = 0; $i < $numchars; $i++) /* Changed to < only sign, otherwise it would be 1 character longer than needed */
    
{
        
$pass .= $chars[$i];
        
shuffle($chars); /* Get repeated characters, would add as an option, but I'm lazy */
    
}

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

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

?>


Added an extra shuffle after each character, so you can get repeated characters too. (I prefer it that way).
Added MiXeD case option
Fixed the length ($i = 0; $i <=$numchars) part.

Last edited by Danltn : 11-03-2007 at 12:36 PM.
Daniel is offline   Reply With Quote
Old 11-04-2007, 09:22 AM   · #3
Mikor
Resident Linux Geek
 
Mikor's Avatar
 
Name: Michael Walker
Location: East Yorkshire, England
Trader Rating: (7)
Join Date: Aug 2005
Posts: 2,254
NP$: 272.30 (Donate)
Mikor is a name known to allMikor is a name known to allMikor is a name known to allMikor is a name known to allMikor is a name known to allMikor is a name known to all
Both good, but heres a function I made a while ago and have been using, it may not be as customizable, but the passwords are very difficult to guess:
PHP Code:
<?php
function prand($len = 10){
     
$pass = '';
     for(
$i = 0; $i < $len; $i ++){
          
$pass .= chr(rand(33, 126));
     }
     return
$pass;
}

echo
prand();
?>
__________________
Michael Walker @ http://me.yarrt.com

NEW COMPUTING BLOG: http://blog.yarrt.com
Mikor is offline   Reply With Quote
Old 02-05-2008, 03:42 PM   · #4
jimmysanders
New Member
 
Trader Rating: (0)
Join Date: Feb 2008
Posts: 9
NP$: 0.00 (Donate)
jimmysanders is an unknown quantity at this point
i had to go for the smallest one

PHP Code:
function randomPassword($length = 8) {
    return    
substr(base64_encode(md5(time())), 0, $length);
}



creates random string of A–Z, a–z, and 0–9 of max of 42ish chars
jimmysanders is offline   Reply With Quote
Old 02-18-2008, 05:53 PM   · #5
unknowngiver
Senior Member
 
Name: Zubair
Location: Ontario Canada
Trader Rating: (53)
Join Date: May 2005
Posts: 2,741
NP$: 713.15 (Donate)
unknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to allunknowngiver is a name known to all
Originally Posted by jimmysanders
i had to go for the smallest one

PHP Code:
function randomPassword($length = 8) {
    return    
substr(base64_encode(md5(time())), 0, $length);
}



creates random string of A–Z, a–z, and 0–9 of max of 42ish chars


lol protection much...base64 and md5 encryption lol
unknowngiver is offline   Reply With Quote
Old 02-19-2008, 02:24 AM   · #6
Daniel
Danltn.com
 
Daniel's Avatar
 
Name: Daniel Neville
Location: Danltn.com / Nottingham, UK
Trader Rating: (65)
Join Date: May 2007
Posts: 1,162
NP$: 638.56 (Donate)
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
Ethan Allen Fund Ethan Allen Fund
Originally Posted by unknowngiver
Originally Posted by jimmysanders
i had to go for the smallest one

PHP Code:
function randomPassword($length = 8) {
    return    
substr(base64_encode(md5(time())), 0, $length);
}



creates random string of A–Z, a–z, and 0–9 of max of 42ish chars


lol protection much...base64 and md5 encryption lol



Not very secure, if you knew say what time roughly they made it, and how long, it could easily be cracked.

Dan
Daniel is offline   Reply With Quote
Reply

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


Site Sponsors
Thousand Dollar Profits Join now! Thousand Dollar Profits
Advertise your business at NamePros
All times are GMT -7. The time now is 02:51 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0