<?php function generatePassword($prefix = null) { $length = 48; $string = ''; if (null !== $prefix) { $string .= preg_replace('/[^a-zA-Z]/', '', $prefix); $string .= bin2hex(openssl_random_pseudo_bytes($length - strlen($string))); } else { $string .= bin2hex(openssl_random_pseudo_bytes($length)); } return $string; }