TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Script Giveaway (http://www.talkphp.com/script-giveaway/)
-   -   Password generator (http://www.talkphp.com/script-giveaway/1696-password-generator.html)

Rizza 12-10-2007 02:38 PM

Password generator
 
Figured I'd give away my password generator.

PHP Code:

public function generatePassword($length 10) {
    
// Build an arrays of consonants and vowels
    
$consSingle str_split('bcdghjklmnprstuvw');
    
$consDouble str_split('trcrbrfrthdrchphwrstspswprslcl'2);
    
$cons       array_merge($consSingle$consDouble);
    
$vowels     str_split('aeiou');
    
$numbers    = array(1234567890);
    
    
// Create the random password
    
$password '';
    
srand((double) microtime() * 1000000);
    for (
$i 0$i $length$i++) {
        
// Alternate between upper and lower case
        
$casing = (rand(01))? 'strtoupper' 'strtolower';
        
        
// Construct the password by a series of constanent + number + vowel.
        
$password .= (
            
$casing($consmt_rand(031) ])
            . 
$numbersmt_rand(09) ]
            . 
$casing($vowelsmt_rand(04) ])
        );
    }
    
    
// Cut string and return password to correct length
    
return substr($password0$length);


Usage:

PHP Code:

$pass generatePassword();
$enc md5('pew! pew! pew!' $pass); 


Village Idiot 12-10-2007 07:18 PM

Wouldn't it be easier just to output random characters? That way you could choose length and mix caps. MD5 outputs 35 chars, thats longer then most people have for passwords.

Jay 12-10-2007 08:53 PM

Avoid using str_split when you don't have to.. initializing the array yourself is a lot more efficient. str_split, and other methods that take care of initiliazing, were made for the manipulation of un-controllable data and such.

And as VI already said.. Just do random letters! Use uniqid() and MD5

PHP Code:

$pass substrmd5uniqidmt_rand(), true ) ), 0mt_rand512 ) ); 


Wildhoney 12-10-2007 10:21 PM

Can I just say that MD5 actually outputs string of 32 characters, not 35.

Village Idiot 12-11-2007 02:47 AM

Quote:

Originally Posted by Wildhoney (Post 6195)
Can I just say that MD5 actually outputs string of 32 characters, not 35.

I should really consider learning how to count one of these days...

Andrew 12-11-2007 04:29 AM

You could just use md5() on time() and then randomly pick a 10-char sequence from the resulting hash.. though, I'm not sure how easily that could result in duplicates (HIGHLY unlikely, though).

Jay 12-11-2007 05:04 AM

You can use a lot of things..

PHP Code:

$pass substrmd5mt_rand() ), 0mt_rand612 ) );
$pass substruniqidmt_rand(), true ), 0mt_rand612 ) );
// it goes on and on xD 



All times are GMT. The time now is 08:37 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0