I do not understand the logic here. How do we know that the hash has changed? I do not see any if statement with a comparison.

If the logic for generating the authname/hash has changed generally I would expect this code to run in a hook_update() - not here.