Here’s a quick function to generate a password. All you have to do is call it passing the length of your required password as an argument.
PHP
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php function generatePassword($intNumOfChars) { if (is_numeric($intNumOfChars) && ($intNumOfChars > 0)) { $strChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_"; for ($i = 0; $i < $intNumOfChars; $i ++) { $strPassword .= $strChars[rand(0, strlen($strChars)-1)]; } } return $strPassword; } ?> |