I'm currently playing with mosquitto's(https://github.com/eclipse/mosquitto) password generation tool , mosquitto_passwd
, I don't really know a lot about hashes algorithms , salts and so on , but one thing I think I understood is how to verify credentials for example : a password is hashed using a certain algorithm , stored , and each time we want to check if a user got the correct password , we hash the input with the same algorithm , and if the hash is the same with the one stored , it would mean that it is the same password.
But when I generate hashes for the same password using mosquitto , I see that these hashes are not the same :
$ mosquitto_passwd -H sha512 -b passfile user password
generates :
$6$Bu5dTpOWUYWMXZFk$unOkjDIots1jbOhzdthqXrz3WQ9uSx1ZmwGHlpBivtSMdysin+97xyJndbB1T3sIaLG4JxH0hPYHCXG3+H6z5Q==
the first time , and
$6$LL/Vto2dvR5rO/KR$PXoQIqiahL0vvpFZt091Q3tFrNHcf+MykrqmfVWPGnAMDHcdI1MbeF50NAWAyasbhGjcE0GyAN+CiB88bMV+bg==
the second.
The format of the hash is $hashtype$salt$hash , $6$ is for sha512 , and the rest is salt + hash.
By looking at the source code (src/password_mosq.c : int pw_hash()) , I noticed that the salt is randomly generated.
What I'm struggling to understand , is how is the program supposed to check the validity of a password if each hashing of this password is different?
Suppose I want to crack this hash using a wordlist , how would I compute the hash that needs to be compared to the one in the database ?