Posted By

svenito on 12/11/08


Tagged

password random generator


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

vali29


random pass generator


 / Published in: PHP
 

  1. function generatePassword ($length = 8) {
  2. $password = "";
  3. $possible = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-$!?][";
  4.  
  5. $i = 0;
  6. // add random characters to $password until $length is reached
  7. while ($i < $length) {
  8. // pick a random character from the possible ones
  9. $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
  10. // we don't want this character if it's already in the password
  11. if (!strstr($password, $char)) {
  12. $password .= $char;
  13. $i++;
  14. }
  15. }
  16. return $password;
  17. }

Report this snippet  

You need to login to post a comment.