Skip to content

Instantly share code, notes, and snippets.

@dave-jay
Created May 21, 2013 05:31
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save dave-jay/5617664 to your computer and use it in GitHub Desktop.
<?php
function generate_password($length = 12, $special_chars = true) {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
if ($special_chars)
$chars .= '!@#$%^&*()';
$password = '';
for ($i = 0; $i < $length; $i++)
$password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
return $password;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment