How should the salt be formatted and what alphabet should it be in when using the "crypt" function in PHP?

When using the "crypt" function in PHP, the salt should be formatted with a specific prefix indicating the algorithm to use (e.g., "$2a$" for bcrypt) followed by the actual salt value. The salt should be in the alphabet consisting of the characters [./0-9A-Za-z]. This ensures compatibility and security when hashing passwords using the "crypt" function.

$salt = '$2a$10$' . substr(str_replace('+', '.', base64_encode(random_bytes(22))), 0, 22);
$password = 'password123';
$hashed_password = crypt($password, $salt);