Building on the accepted answer. I wanted to verify that the password hash matched with the password which was initially set - or thought to be set.
First I don't want passwords to show up in the command line history, so for
# cat > pass.txt
mypasswd1
<ctrl>+d
# cat > badpass.txt
faulty
<ctrl>+d
Then I create an MD5 hash:
# RET=$(openssl passwd -1 -in pass.txt)
# echo $RET
$1$nhyuaE7S$ld2wuucUlRUQE8iAnJhjF/
The "salt" is the third field, as separated by $ (including the leading/empty field). Saving the "salt"
# SALT=$(echo $RET | cut -d\$ -f 3)
# echo $SALT
nhyuaE7S
So to see if the password actually matched the MD5 hash I compare the hash I have saved in the $RET variable with the first line of the "test".
# echo "$RET" ; openssl passwd -1 -salt "$SALT" $(cat pass.txt) "$RET"
$1$nhyuaE7S$ld2wuucUlRUQE8iAnJhjF/
$1$nhyuaE7S$ld2wuucUlRUQE8iAnJhjF/
$1$nhyuaE7S$3pGvIF7UwuvhJjXzR4Yb.0
They seem to match, let's have diff to check for us:
# diff <(echo "$RET") <(openssl passwd -1 -salt "$SALT" $(cat pass.txt) "$RET" | head -1)
# echo $?
0
So far so good, but lets also check with the "bad" password to see that we don't have a match.
# echo "$RET" ; openssl passwd -1 -salt "$SALT" $(cat badpass.txt) "$RET"
$1$nhyuaE7S$ld2wuucUlRUQE8iAnJhjF/
$1$nhyuaE7S$t6MTdY2QafzUtBMMVzf5B.
$1$nhyuaE7S$3pGvIF7UwuvhJjXzR4Yb.0
# diff <(echo "$RET") <(openssl passwd -1 -salt "$SALT" $(cat badpass.txt) "$RET" | head -1) >/dev/null
# echo $?
1
So now we have a test which actually can "prove" that the stored MD5 hash, i.e. in a config file, match the password we think is the correct one.
Please inform in the comments if any of my assumptions are mistaken or incorrect.