2

I'm developing an application which is distributed on a VM. The default password is always the same, but it's hash in /etc/shadow changes with every release. How can I programmatically (e.g., from a bash script) find out whether the password was changed? Checking the hash is not an option because if the password was changed to something else and back, it will be different. I also want to keep the check as simple as possible.

3
  • 2
    chage -l <user> should give you this information.
    – fedorqui
    Commented Sep 8, 2014 at 12:05
  • you passwd are in the md5 form (e.g. $1$salt$nWwtt7njwVig74jTAfjuG/ ) ?
    – Archemar
    Commented Sep 8, 2014 at 12:07
  • No, they are like this only when changed. This is actually one of the options I'm considering, to check for length/structure. They look like this: 8yInpa/Ksc9wA
    – JohnEye
    Commented Sep 8, 2014 at 12:32

1 Answer 1

1

If you know the passwd, you can generate de md5 string with

 openssl passwd -salt $salt -1 foo

The point is getting the value for "$salt". This can be retrieved using awk on the crypted passwd from /etc/shadow.

 echo $CRYPTIC | awk -F\$ '{print $3}'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .