If the Cookbook instructions do not result in met expectations, a beginner needs to go beyond assuming and start understanding.
However, the power of the pre-written code also obstructs the transparency of what is going on. In the tutorial example project I created an email + password before configuring the hashing. From the following I expected that resetting this password (by its exact self) would lead to a hashed password, which did not happen.
“Note bcrypt will generate a different hash even for the same password saved twice.”
// in src/Model/Entity/User.php
use Authentication\PasswordHasher\DefaultPasswordHasher;
class User extends Entity
{
// ... other methods
// **Automatically hash passwords when they are changed.**
protected function _setPassword(string $password)
{
$hasher = new DefaultPasswordHasher();
return $hasher->hash($password);
}
}
add() and edit() in UsersController.php use newEntity() and patchEntity(), which should thus both use _setPassword in a certain way.
After searching through the complete project directories I found out that newEntity() patchEntity() are both empty functions in RepositoryInterface.php. So I couldn’t figure out the mechanism and troubleshoot by myself based on the code. Are there other ways to understand the code or shouldn’t I even bother to try?
(This is a trivial example, I found out that the re-hashing of the same password only works for already hashed passwords. I assume that without hashing, the edited password is not really _set if it is identical to the initial password. It would be nice to be able to confirm this by the code though, especially for future encounters. )