JDT |
FREE Downloads |
|
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 Go back to PHP Tutorials home page Go back to Tutorials home page
|
|