Your Ad Here

 Navigation
Home
Source code
Tutorials
RSS feeds
Articles
Wordpress plugins
Books
Sample Chapters
Software
Downloads
Hosting
manuals
Script directory
Training
Our Links




 Sponsors
 Links
finance products
wwwstores
gambling sites
 Downloads
dzphp editor
EasyPHP
mysql_phpgenerator
php-studio-trial
phpdesigner_7_2_5
phpMyAdmin-3.4.3.2
/phptriad2-2-1
phpxedit_321
rapidphp 2011
WampServer2.1d-x64
WampServer2.1e-x32
xampp-win32-1.7.4-VC6-installer
xampplite-win32-1.7.3
 Misc
Webmaster Resources
Only PHP
ScriptSearch.com
Scripts.com - Get the best scripts NOW!
AndreaPHP Programming

Valid XHTML 1.0 Transitional


Valid CSS!

PHP Password Function

When developing a web application that enables 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 straightforward 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", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z");

$firstletter = $letterlist[rand(0,count($letterlist) - 1)];

$secondletter = $letterlist[rand(0,count($letterlist) - 1)];

$thirdletter = $letterlist[rand(0,count($letterlist) - 1)];

$fourthletter = $letterlist[rand(0,count($letterlist) - 1)];

$fifthletter = $letterlist[rand(0,count($letterlist) - 1)];

$sixthletter = $letterlist[rand(0,count($letterlist) - 1)];

$number1 = rand(10,99);

$number2 = rand(10,99);

$word = $firstletter.$number1.$secondletter.$thirdletter.$fourthletter.$number2.$fifthletter.$sixthletter;

return $word;

}

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.
About the Author: John Dixon is a web developer and technical author. These days, John spends most of his time developing dynamic database-driven websites using PHP and MySQL.

Go to http://www.computernostalgia.net to view one of John's sites. This site contains articles and photos relating to the history of the computer.

To find out more about John's work, go to http://www.dixondevelopment.co.uk

 


 




Books
 Sponsors


 Random Code
Display meta tags(internet)
decimal to binary conversion(math)
Currency convertor(application)
 Random Article
  Network
Programming resources
Tutorials directory
Hosting resources
ASP site
Domain names
Progged
Maxi directory
bigarticle : free articles
A Code
Code N Tutorials
Get PHP
Programmers help




beginners PHP Copyright © 2004 onwards by beginnersPHP.