diff options
author | Ian Moffett <ian@osmora.org> | 2024-09-28 01:10:13 -0400 |
---|---|---|
committer | Ian Moffett <ian@osmora.org> | 2024-09-28 01:10:13 -0400 |
commit | 9a44a928ccebdceb5a4dd9a4d67168cc04d1227f (patch) | |
tree | 8f64888b89e9ffe6f5dd6fd541623b15184ccbb9 /tools | |
parent | 2229015eec1804cf33225fd28931a9e43e1fdf2e (diff) |
ostp.d: auth: Add user authentication
Signed-off-by: Ian Moffett <ian@osmora.org>
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/pwcheck | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/tools/pwcheck b/tools/pwcheck new file mode 100755 index 0000000..85cd6c3 --- /dev/null +++ b/tools/pwcheck @@ -0,0 +1,43 @@ +#!/bin/bash + +# Get the current user's username +USER="" +PW="" + +if [[ $# -lt 2 ]] +then + echo "Usage: pwcheck [username] [password]" + exit 1 +fi + +PW_HASH="" +USER="$1" +PW="$2" + +# Get the hashed password from /etc/shadow for the current user +SHADOW_ENTRY=$(sudo grep "^$USER:" /etc/shadow) + +if [ -z "$SHADOW_ENTRY" ]; then + echo "User not found in /etc/shadow" + exit 1 +fi + +HASHED_PW=$(echo "$SHADOW_ENTRY" | cut -d':' -f2) +SALT=$(echo "$HASHED_PW" | cut -d'$' -f3) +ALGORITHM=$(echo "$HASHED_PW" | cut -d'$' -f2) + +# Yescrypt +if [[ $ALGORITHM == "y" ]] +then + HASHED_PW=$(echo "$SHADOW_ENTRY" | cut -d':' -f2) + SALT=$(echo "$HASHED_PW" | cut -d'$' -f4) + PW_HASH=$(mkpasswd "$PW" "\$y\$j9T\$$SALT") +else + PW_HASH=$(echo "$PW" | openssl passwd -stdin -"$ALGORITHM" -salt "$SALT") +fi + +if [ "$PW_HASH" == "$HASHED_PW" ]; then + exit 0 +else + exit 1 +fi |