fork download
  1. <?php
  2.  
  3. function generateRandomPassword($length = 12) {
  4. $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
  5. $specialCharacters = '!@#$%^&*()-_+={}[]|;:\'",.<>/?';
  6. $numbers = '0123456789';
  7. $password = '';
  8.  
  9. // Ensure at least one special character
  10. $password .= $specialCharacters[rand(0, strlen($specialCharacters) - 1)];
  11. $length--;
  12.  
  13. // Ensure at least one number
  14. $password .= $numbers[rand(0, strlen($numbers) - 1)];
  15. $length--;
  16.  
  17. // Generate the rest of the password
  18. for ($i = 0; $i < $length; $i++) {
  19. $password .= $characters[rand(0, strlen($characters) - 1)];
  20. }
  21.  
  22. // Shuffle the password to mix special characters and numbers
  23. return str_shuffle($password);
  24. }
  25.  
  26. echo generateRandomPassword(8);
Success #stdin #stdout 0.02s 25840KB
stdin
Standard input is empty
stdout
9_YbnCgF