Random password


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <?php
  2. /**
  3. * Random Password Generator
  4. * @public
  5. * @param int $length Length of password to generate
  6. * @return string Returns randomised password
  7. */
  8. function randomPword($length)
  9. {
  10. $seed = 'ABC123DEF456GHI789JKL0MNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
  11. $seedLength = strlen($seed);
  12. $random = '';
  13. for ($i=1; $i <= $length; $i++)
  14. {
  15. $charPos = mt_rand(0, ($seedLength - 1));
  16. $singleChar = substr($seed, $charPos, 1);
  17. $random .= $singleChar;
  18. }
  19. return $random;
  20. }
  21. ?>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.