Sr. Web Developer
mediabistro.com
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume

Generating pronounceable passwords
I used the first 300 lines of the /usr/dict/words file in my Solaris box and save them into the file mywords, you can use any list of words you would like. Also, if you desire to have a better random generator, use the Mersenne Twister functions (see the manual entries for mt_rand() and mt_srand() for their description and links to more information).
Creating a function
Of course, we can make all of this into a function that you can drop in your scripts:
List 2: function ppassgen()

<?php

/*
* Pronounceable password generator
* version 1.0 - made into a function
* Inspired by a question made by: georgcantor_at_geocities.com
* in the PHPBuilder discussion forum
* (c) Jesus M. Castagnetto, 1999
* GPL'd code, see www.fsf.org for more info
*/


/*
* function ppassgen()
* parameters:
* $words = the name of the file w/ the words (one per line)
*      or and array of words
* $min = the minimum number of words per password
* $max = the maximum number of words per password
* $cutoff = the minimum number of characters per word
* $sep = separator for the words in the password
*/

function ppassgen($words= "mywords", $min=2, $max=4, $cutoff=5, $sep= "_") {

    if(
is_array($words)) {
        
/* if we have passed and array of words, use it */
        
$word_arr =  "words";
         
/*
        while(list($k,$v) = each(${$word_arr})) {
            echo "$k $v<BR>";
        }
        */
    
} else {
        
/* read the external file into an array */
        
$fp = fopen($words, "r");

        if (!
fp) {
            echo  
"[ERROR}: Could not open file $words<BR>\n";
            exit;
        } else {
            
/* assuming words of up to 127 characters */
            
$word_arr =  "ext_arr";
            while(!
feof($fp)) {
                
$tword = trim(fgets($fp,128));

                
/* check for minimum length and for exclusion of numbers */
                
if ((strlen($tword) >= $cut_off) && !ereg( "[0-9]",$tword)) {
                    
$ext_arr[] = strtolower($tword);
                }
            }
            
fclose($fp);
        }
    }

    
/* size of array of words */
    
$size_word_arr = count(${$word_arr});

    
/* generate the password */
    
srand((double)microtime()*1000000);

    
/* or use the Mersenne Twister functions */
    //mt_srand((double)microtime()*1000000);

    /* for a password of a fixed word number, min = max */
    
$n_words = ($min == $max)? $min : rand($min,$max);

    
/* or use the Mersenne Twister for a better random */
    //$n_words = ($min == $max)? $min : mt_rand($min,$max);

    
for ($i=0; $i<$n_words; $i++) {
        
$pass .= ${$word_arr}[rand(0,($size_word_arr - 1))] . $sep;
    }
    
/* return the password minus the last separator */
    
return substr($pass,0,-1*strlen($sep));
}


/* test the function */

/* generate 10 passwords using the default */
for ($j=0; $j < 10; $j++) {
    echo
ppassgen() .  "<BR>\n";
}

/* change some paramaters and use our own separator */
echo  "<HR>\n";
echo
ppassgen( "mywords",3,4,7, "**") .  "<BR>\n";

/* give our own array to the function and generate a 2 word password */
$nwords = array( "cat", "mouse", "dog", "house", "surfboard", "kirima");
echo
ppassgen($nwords,2,2,3) . "<BR>\n";

?>
[ Next Page ]

[Page 1]  [Page 2]  


Comments:
re: pronouncable is importantSaint05/15/03 17:56
RE: easy to remember gibberishJames11/28/02 20:13
RE: See FIPS-181tom11/07/02 13:58
Big Mistakegilhad10/30/02 09:26
RE: Think like an Application ArchitectLee08/21/02 17:04
easy to remember gibberishAndrew Penry07/27/02 19:39
RE: Think like an Application ArchitectJon Nadal07/24/02 15:33
Think like an Application ArchitectLee04/16/02 22:01
RE: Another possible accessMike Marinescu03/01/02 01:53
RE: See FIPS-181mike01/09/02 10:52
QuestionJeff Williams12/20/01 22:05
Parse ErrorVijay Avarachen11/26/01 06:45
RE: One (of many) alternative solutionBrian Clancey08/23/01 16:49
RE: Another possible accessDavid Altherr07/06/01 12:29
RE: One (of many) alternative solutionHugh Bothwell06/23/01 11:22
RE: html editor and coursesJames Diss06/07/01 07:39
How about alternate vowels & consonants?Tom Westmacott05/07/01 12:29
One (of many) alternative solutionJack Healy05/03/01 09:29
RE: Another possible accessJeremy Weiskotten04/19/01 18:59
html editor and coursesMarlon Benjamin03/08/01 11:01
See FIPS-181Andy03/07/01 17:24
RE: Another possible accessKatie03/02/01 19:19
RE: Insecurity.Bill Canaday02/26/01 15:12
RE: Insecurity.Jay02/21/01 11:26
RE: Insecurity.Lance Sloan02/08/01 15:56
RE: Insecurity.Allen02/03/01 11:49
RE: Another possible accessMartin Scheffler01/11/01 06:17
RE: Insecurity.Matt12/15/00 17:50
Insecurity.Michal Zajaczkowski11/27/00 06:34
Another possible accessTomas Krojzl09/16/00 09:16
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.