Web Producer w/ Brilliance
Aquent
US-CA-San Rafael

Justtechjobs.com Post A Job | Post A Resume

Generating pronounceable passwords
The problem
Just today (1999/04/29), someone asked in the PHPBuilder discussion boards if there was a way to generate random but pronounceable passwords. I guess something like the ubiquitous passwords you find in each of the AOL CD-ROMs that litter our mailboxes :)
In this article we will show how to do just that, with the constrains that we do not want to have number containing words in your output, and that we want to be able to specify the length of the words used.
The simplest way I could think to accomplish this would be to:
  1. Have a set of words (maybe in an array)
  2. Select the number of words to use in the password
  3. Pick the words and concatenate them
In the listing below, we will read a list of words from a file into an array, and then use the random functions in PHP to generate the password.
List 1: a simple pronounceable password generator

<?php

/*
* Pronounceable password generator
* version 1.0beta
* 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
*/

$words =  "mywords";     /* the file w/ the words */
$cut_off = 5;     /* minimum number of letters in each word */
$min_pass = 2;     /* minimum number of words in password */
$max_pass = 3;     /* maximum number of words in password */

/* 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 */
    
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)) {
            
$word[] = strtolower($tword);
        }
    }
    
fclose($fp);
}

/* generate the password */

$size_word = count($word);
srand((double)microtime()*1000000);
$n_words = rand($min_pass,$max_pass);

/* use the Mersenne Twister for a better random */
#mt_srand((double)microtime()*1000000);
#$n_words = mt_rand($min_pass,$max_pass);

for ($i=0; $i < $n_words; $i++) {
    
$pass .= $word[rand(0,($size_word - 1))] .  "_";
}

/* print the password */
echo substr($pass,0,-1). "<BR>\n";

?>
If you run the program listed above, the output would be (for example):

addressograph_accessible_adapt_acrid
[ Next Page ]


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.