It shouldn’t, everything CakePHP uses password_hash
and password_verify
under the hood (source).
This means that the hash output will contain everything that’s needed:
- The algorithm used
- the salt
- the cost
- the hash itself
All password_verify
does is take the first 3 parameters and runs them through the algorithm again then compares against the hash to see if they match.
Here’s some illustrative code to show what PHP does to create the hash:
$password = 'lamepassword';
$salt = 'lamesalt'; // Obviously this changes every time
$algo = 'sha256';
$rounds = 10;
function makeHash(string $data, string $salt, string $algo) {
return hash($algo, $salt . $data);
}
$hash = $password;
for($round = 0; $round <= $rounds; $round++) {
$hash = makeHash($password, $salt, $algo);
}
var_dump($algo . ':' . $rounds . ':' . $salt . ':' . $hash); // string(83) "sha256:10:lamesalt:75d640c3f13991f3932e1337c4878d87602abd01d56766da77fd0ff5b2cb936b"
Now for verification, it does the following (again, just for illustration):
$password = 'lamepassword';
$hashStr = "sha256:10:lamesalt:75d640c3f13991f3932e1337c4878d87602abd01d56766da77fd0ff5b2cb936b";
list($algo, $rounds, $salt, $expectedHash) = explode(':', $hashStr);
function makeHash(string $data, string $salt, string $algo) {
return hash($algo, $salt . $data);
}
$hash = $password;
for($round = 0; $round <= $rounds; $round++) {
$hash = makeHash($password, $salt, $algo);
}
var_dump($hash === $expectedHash); // bool(true)
If the user were to give the wrong password, the expected hash and the hash we get from the input password won’t match up.
The hash-string itself contains all data needed to do the verification, this is exactly to prevent cases where changing the algorithms in the code would prevent user login.
Developers can check whether the password needs a rehash using \Cake\Auth\DefaultPasswordHasher#needsRehash
.
Additionally, salts should always be unique when hashing passwords.
- Salts are “unique” per password (to combat the effectiveness of so-called “rainbow tables”).
- Peppers are “unique” per app (but are rarely used when hashing passwords, atleast, in PHP).
This also shouldn’t matter as the only difference here is how the browser and server will communicate.
The data (and thus the password) will be the same, it’s just wrapped with some encryption so it is harder to intercept.
To CakePHP, the data (and thus the password) it’ll see will be basically the same.