Password Generator Function in PHP

The following GeneratePassword() function lets you to create a random password whether for your custom site or for personal use.

The function contains 1 parameter which is $len.
  • $len - The number of password characters.

You can also define the set of characters "CHARS" on your parent class.

Code:
<?php
define("CHARS", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_+@(!)<>");

function GeneratePassword($len = 10)

{
    $pass = ''; //Initialize random password variable
    $char = str_split(CHARS);
    $count = strlen(CHARS) - 1;
    for ($i = 0; $i < $len; ++$i)
    {
        $index = rand(1, $count);
        $pass .= $char[$index];
    }
        return $pass;

}
?>

Usage:
<?php
      echo GeneratePassword(12);
?> 

Output:
LnxLLo+pGHiD  

Comments

Popular posts from this blog

How to Create a Configuration.INI Files in VB6

How to Make Windows Form Transparent using Visual Basic 6/VB6

How to Set Windows Form Always on Top of Other Applications in VB6