Random Password


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



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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.