JDT

 

FREE Downloads
Articles
Tutorials

 

Using PHP to Create a Simple Password Generator - Version 1


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 tutorial shows how to create a simple PHP function to generate a password.

The function, generate_password(), shown below generates a password

function generate_password()
{
$source = "ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz";

$out = "";

for ($i = 1; $i <= 10; $i++)
{
	$pick = rand(0,60);
	$out .= substr($source, $pick ,1);
}

return $out;

return true;

}

This function could be called as follows:


# Generate a random password
$pswd = generate_password();

The complexity of the generated password can be varied by changing the variety and number of characters in $source, and/or the number of times the 'for' loop is executed. If you change $source, remember to also change 'rand' in the 'for' loop. For example, if $source contains 30 characters, change 'rand' to rand(0,29).

Go to Using PHP to Create a Simple Password Generator - Version 1 to see an alternative password generator.


Author: Backrubber
John Dixon Technology Ltd







Go back to PHP Tutorials home page

Go back to Tutorials home page



Earnings Tracker is John Dixon Technology's FREE accounting and bookkeeping software tool.

Aimed at contractors and freelancers, Earnings Tracker enables you to perform bookkeeping and accounting tasks, helping you to keep track of your company's earnings and outgoings.

The software is written in PHP and MySQL and is available to use for FREE online, or as a FREE download.

Earnings Tracker can also be used simply as a dividend, corporation tax, or VAT calculator.

Need free accounting software
 


JDT

Copyright Notice for John Dixon Technology Ltd

Privacy Statement

Terms & Conditions