Why does phpass return different hashes for the same input string?

476 views Asked by At

I'm used to having hashing algorythms return always the same hash.

Why does phpass library return always different hashes?

Does it have something to do with the IV? (I never fully understood that concept)

<?php

require __DIR__ . '/PasswordHash.php';

$hasher = new PasswordHash(11,false);

$password = 'bla123';

echo $hash = $hasher->hashPassword($password); // different for each request
2

There are 2 answers

0
HappyDeveloper On BEST ANSWER

It uses crypt(), which already generates different hashes for the same string. It hashes each password with a different key, and it stores the key inside the hash (it's public).

0
AudioBubble On

according to this section "What if the user already exists?" it's normal behaviour of this library