I have been trying to understand password salting and hashing for a project I am working on. From the responses to a previous question I saw the php manual for password_hash as a good way to start.
However, when trying out the code on that page, I get an error that I haven't been able to resolve.
Code:
<?php
/**
* Note that the salt here is randomly generated.
* Never use a static salt or one that is not randomly generated.
*
* For the VAST majority of use-cases, let password_hash generate the salt randomly for you
*/
$options = [
'cost' => 11,
'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
];
echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options)."\n";
?>
Error:
Parse error: syntax error, unexpected '[' in /home/content/##/######/html/TESTINGFOLDER/HashNSalt.php on line 8
According to the manual -
The above example will output:
$2y$11$q5MkhSBtlsJcNEVsYh64a.aCluzHnGog7TQAKVmQwO9C8xb.t89F.
Line 8 is
$options = [
Can someone here explain why I am getting this error - especially since I have copied and pasted this into my test page from the PHP Manual itself? I am still in the early stages of learning authentication/ php etc and depend on the manual, stackexchange/overflow to understand why things don't work the way they should. I am totally stumped when code I find in the manual doesn't work the way it should!