create a password with symbols in php

To create a password with symbols in PHP, you can use the str_shuffle function along with a set of characters that you deem as symbols. Here's an example function that generates a random password with letters, numbers, and symbols:

main.php
function generatePassword($length = 8) {
  // Define symbols to use
  $symbols = '!@#$%^&*()_+-=[]{},.';
  
  // Define character sets
  $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
  
  // Add symbols to character set
  $chars .= $symbols;
  
  // Shuffle the characters and get a random substring of the desired length
  $password = substr(str_shuffle($chars), 0, $length);
  
  return $password;
}

// Usage:
$password = generatePassword(12); // Generates a random password with 12 characters
echo $password;
542 chars
20 lines

This function defines a set of symbols to use, along with a set of letters and numbers. It then concatenates these sets together, shuffles them, and selects a random substring of the desired length to return as the password.

Note that it's important to use a strong password when dealing with sensitive information. The length of the password should be at least 12 characters and should include a mix of uppercase and lowercase letters, numbers, and symbols. Additionally, password should be securely stored using a hashing algorithm like bcrypt.

gistlibby LogSnag