generate a password code example

Example 1: random password generator

function rand_string( $length ) {
	$str = "";
	$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

	$size = strlen( $chars );
	for( $i = 0; $i < $length; $i++ ) {
		$str .= $chars[ rand( 0, $size - 1 ) ];
	}

	return $str;
}
//and call the function this way:
$mypass = rand_string(10);

Example 2: password generator

const Numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
  const Names = ["Aaran", "Aaren", "Aodeba","Zaid", "Zain", "Zaine", "Zaineddine", "Zainedin", "Zak", "Zakaria", "Zakariya", "Zakary", "Zaki", "Zakir", "Zakk", "Zamaar", "Zander", "Zane", "Zarran", "Zayd", "Zayn", "Zayne", "Ze", "Zechariah", "Zeek", "Zeeshan", "Zeid", "Zein", "Zen", "Zendel", "Zenith", "Zennon", "Zeph", "Zerah", "Zhen", "Zhi", "Zhong", "Zhuo", "Zi", "Zidane", "Zijie", "Zinedine", "Zion", "Zishan", "Ziya", "Ziyaan", "Zohaib", "Zohair", "Zoubaeir", "Zubair", "Zubayr", "Zuriel"]
  const Symbols = ["#", "£", "@", "%", "?", "!", "+", "$", "-", "*"]
  const RandomName = Names[Math.floor(Math.random() * Names.length)];
  const RandomNumber = Numbers[Math.floor(Math.random() * Numbers.length)];
  const RandomNumber2 = Numbers[Math.floor(Math.random() * Numbers.length)];
  const RandomSymbol = Symbols[Math.floor(Math.random() * Symbols.length)];
  const RandomSymbol2 = Symbols[Math.floor(Math.random() * Symbols.length)];
  const RandomSymbol3 = Symbols[Math.floor(Math.random() * Symbols.length)];
  const RandomSymbol4 = Symbols[Math.floor(Math.random() * Symbols.length)];
  const Password = `${RandomNumber2}${RandomSymbol}${RandomName}${RandomNumber}${RandomSymbol4}`
  const Password2 = `${RandomNumber2}${RandomSymbol2}${RandomName}${RandomSymbol3}${RandomSymbol4}`
  const Password3 = `${RandomNumber}${RandomNumber2}${RandomName}${RandomNumber}${RandomSymbol4}`
  const Password4 = `${RandomSymbol2}${RandomSymbol3}${RandomName}${RandomNumber2}${RandomNumber}`
  const Passwords = [Password, Password2, Password3, Password4]
  const GeneratedPassword = Passwords[Math.floor(Math.random() * Passwords.length)];
  const GeneratedPasswordToLowerCase = GeneratedPassword.toLowerCase()
  /* Print The Passwords*/
  console.log(GeneratedPassword)
  console.log(GeneratedPasswordToLowerCase)

Example 3: generate random password

var btn = document.getElementById("btn");

btn.addEventListener("click", function generate() {
  var generatePassword = "";
  var password = document.getElementById("password");
  var characters =
    "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*?";

  for (var i = 0; i < 10; i++) {
    generatePassword += characters.charAt(
      Math.floor(Math.random() * characters.length)
    );
  }
  password.innerHTML = generatePassword;
});