Skip to content

Instantly share code, notes, and snippets.

@mmmunk
Created December 2, 2016 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmmunk/3630e59b6a791c3243f3b9a88a517e35 to your computer and use it in GitHub Desktop.
Save mmmunk/3630e59b6a791c3243f3b9a88a517e35 to your computer and use it in GitHub Desktop.
Script for validating a Linux password. Method SHA-512 (Type ID 6 - first shadow col) expected.
#!/bin/bash
L1=`grep $1 /etc/shadow|cut -d ":" -f 2`
if [ $L1 ]; then
SALT=`echo $L1|cut -d "$" -f 3`
L2=`mkpasswd --salt=$SALT --method=sha-512 $2`
if [ "$L1" == "$L2" ]; then
exit 0
else
exit 1
fi
else
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment