random pass generator


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



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.