Generate password


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



Copy this code and paste it in your HTML
  1. function generatePassword ($length = 16)
  2. {
  3.  
  4. // start with a blank password
  5. $password = "";
  6.  
  7. // define possible characters
  8. $possible = "0123456789bcdfghjkmnpqrstvwxyz";
  9.  
  10. // set up a counter
  11. $i = 0;
  12.  
  13. // add random characters to $password until $length is reached
  14. while ($i < $length) {
  15.  
  16. // pick a random character from the possible ones
  17. $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
  18.  
  19. // we don't want this character if it's already in the password
  20. if (!strstr($password, $char)) {
  21. $password .= $char;
  22. $i++;
  23. }
  24.  
  25. }
  26.  
  27. // done!
  28. return $password;
  29.  
  30. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.