Generate Random Password

Free Scripts :: PHP :: String :: Generate Random Password

Author: Salman Javaid

Website: http://www.salman.be

  • Generate random password.
  • Generate random string.
  • Generate varification code.

Function accepts a length parameter and returns randomly generated password.

Function:
function generatePassword ($length = 2)
{
    $password = "";
    $possible = "0123456789bcdfghjkmnpqrstvwxyz";
    $i = 0;
    while ($i < $length) {
        $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
        if (!strstr($password, $char)) {
            $password .= $char;
            $i++;
        }
    }
    return $password;
}
Calling The Function:
echo generatePassword ($length = 10);
Output:
df1h1rtere

Comments

No comments. Be the first one.

Leave a comment

Full Name*
Comments*
Security Code*

Our Partners

Getty Icons  Salman Creations
Free High Quality Images  Learn Free Languages 
Opal Hosting  R-Tech Solutions
  • Submit a Script

    Click here to submit your script.