Support Forums

Full Version: Advanced Random Password Generator
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Credits and Source: http://www.dreamincode.net/

Description:
Create random passwords with a chosen length and a specified number of numbers. Uses both lower case and capital letters, which are chosen at random. And example is: wep5Q268LtTe

Snippet:
PHP Code:
function passwordGen($length,$nums){
        
$lowLet "abcdefghijklmnopqrstuvwxyz";
        
$highLet "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        
$numbers "123456789";
        
$pass "";
        
$i 1;
        While (
$i <= $length){
            
$type rand(0,1);
            if (
$type == 0){
                if ((
$length-$i+1) > $nums){
                    
$type2 rand(0,1);
                    if (
$type2 == 0){
                        
$ran rand(0,25);
                        
$pass .= $lowLet[$ran];
                    }else{
                        
$ran rand(0,25);
                        
$pass .= $highLet[$ran];
                    }
                }else{
                    
$ran rand(0,8);
                    
$pass .= $numbers[$ran];
                    
$nums--;
                }
            }else{
                if (
$nums 0){
                    
$ran rand(0,8);
                    
$pass .= $numbers[$ran];
                    
$nums--;
                }else{
                    
$type2 rand(0,1);
                    if (
$type2 == 0){
                        
$ran rand(0,25);
                        
$pass .= $lowLet[$ran];
                    }else{
                        
$ran rand(0,25);
                        
$pass .= $highLet[$ran];
                    }
                }
            }
            
$i++;
        }
        return 
$pass;


Instructions: Just add to the appropriate page and call the procedure like passwordGen(12,4) for a password 12 letters long with 4 numbers like in the example: wep5Q268LtTe

Yeye That's It
Just like my own, except in PHP. Looks good.
(11-06-2009, 02:26 PM)Korchidoom Wrote: [ -> ]Just like my own, except in PHP. Looks good.

Good to read that it is useful for you. Thanks for your comments, be happy always Smile