Posted By

iTony on 08/30/08


Tagged

php password random function


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

luman
jfherring


Random password


 / Published in: PHP
 

  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  

You need to login to post a comment.