JDT |
John Dixon |
Using PHP to Create a Simple Password Generator |
||||
|
When developing web applications that enable users to register, it is often necessary to generate a password that would be (typically) emailed to an email address provided by the user at registration time. This article shows how to create a simple PHP function to generate a password. The function, generate_password(), described below generates an eight character password, although it would be very easy to change it so that it generated a shorter or longer password.
function generate_password(){
$letterlist = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
The $letterlist array simply contains all the letters in the alphabet, in both lower and upper case. You could shorten this list, or change the items in the array so that they are, for example, short words instead of individual letters. For example:
$letterlist = array("b", "m", "s");
or
$letterlist = array("ben", "mat", "sus");
but neither of these would produce such a good password. You could also change the $word variable so that it contains fewer characters. For example: $word = $firstletter.$secondletter.$number1; but again, this would produce a less secure password. Author: John Dixon Go back to PHP Tutorials home page Go back to Tutorials home page
|
|
|
|||||
|
© 2007-2009 - John Dixon Technology Ltd |
|||||