PHPBuilder - Generating Pronounceable Passwords Page 3



RSS Twitter
Articles Tricks And Hacks

Generating Pronounceable Passwords - Page 3

by: Jess Castagnetto
|
July 30, 2000

This function can accept as an input the name of the file where your list of words resides, or an array of words. At the beginning of the function you will see that we check whether an array was passed, if so we assing the variable name to the variable <?php example ('$word_arr');?>.
If no array was passed we assume that is a filename (or an URL), attempt to open the file and save the contents to an array taking into account the constrain of the minimum number of letters per word. We then assign the name of the array to the variable <?php example ('$word_arr');?>.
During the generation of the password we make use of the array of words, and the code there is independent on whether the array was passed to the function or created by reading from a file. We accomplish this by referring to the array as <?php example ('${$word_arr}');?>, which the parser will interpret as <?php example ('$words');?> or <?php example ('$ext_arr');?>, depending on the origin of the array. This is an example of the use of variable variables to make general routines.
The test samples show how to use the function to generate passwords using the default values for all parameters, how to change the separator from "_" to "**", and finally how to pass our own array of words and make the function generate password with exactly 2 words.
Running the program in Listing 2, would generate output such as:
   
   acuity_abuilding_abyssinia_actuate
   accuracy_abacus_aborning_abnormal
   ablaze_acquiescent_accomplice
   abbreviate_acme_acton
   accessible_abhorred_absent
   abreact_aaron
   academician_absolution
   abelson_academician
   abstention_adept_abuilding_acropolis
   additive_acreage_acanthus

   about**abc**acidulous

   dog_cat

Further improvements

There are many other things you could improve in this function, for example, you could have 2 or more arrays, one with verbs, another with adjectives and adverbs, and other with nouns, and then use some simple grammatical rules to construct passphrases (e.g. tomatoes fly terribly), which are more difficult to guess than regular passwords and more easy to remember for the user.
We can also improve performance by avoiding the opening of an external file, and then the parsing of it to create the array of words, by having the arrays predefined into an include file or in the same script (also the latter will make your script long).
This and other improvements are (of course) left as an excercise to the reader.
Good luck and have fun.
 
--Jesus M. Castagnetto

« Previous Page
1
|
2
|
3

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Jess Castagnetto

Comment:



Comment:

(Maximum characters: 1200). You have characters left.