Posted By

Eloi on 06/07/09


Tagged

php password random


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Eloi


Random Password


 / Published in: PHP
 

  1. function randPassword() {
  2. $password = '';
  3.  
  4. for ($x = 1; $x <= 8; $x++) {
  5. switch ( rand(1, 3) ) {
  6.  
  7. // Add a random digit, 0-9
  8. case 1:
  9. $password .= rand(0, 9);
  10. break;
  11.  
  12. // Add a random upper-case letter
  13. case 2:
  14. $password .= chr( rand(65, 90) );
  15. break;
  16.  
  17. // Add a random lower-case letter
  18. case 3:
  19. $password .= chr( rand(97, 122) );
  20. break;
  21. }
  22. }
  23.  
  24. return $password;
  25. }

Report this snippet  

You need to login to post a comment.