"; echo "Password: $password
"; echo "Salt (computed as the username's hash): $salt
"; echo "Salted password: $saltedPwd
"; echo "Hash of salted password: $hashedPwd
"; echo "

"; // Same as above but using a function function getPasswordHash_Hex($username, $password) { // Compute hash of salted-password (and salt) from username and password (in hex format) $salt = hash('sha256', $username); // Compute salt as the hash of the username $saltedPwd = $salt . $password; // Get a salted password by combining salt and password $hashedPwd = hash('sha256', $saltedPwd); // Hash the salted password using SHA-256 // Return the password hash and the salt return [ 'hash' => $hashedPwd, 'salt' => $salt ]; } // Example usage of function getPasswordHash $getHasedPwd = getPasswordHash_Hex($username, $password); // Display results echo "Salt (in hex) computed using function getPasswordHash_Hex: " . $getHasedPwd['salt'] . "
"; echo "Hash (in hex) computed using function getPasswordHash_Hex: " . $getHasedPwd['hash'] . "
"; ?>