Last active
March 8, 2025 07:26
-
-
Save chulkilee/6798626 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# https://httpd.apache.org/docs/2.2/misc/password_encryptions.html | |
HTPASSWD=$1 | |
USERNAME=$2 | |
PASSWORD=$3 | |
ENTRY=`cat $HTPASSWD | grep "^$USERNAME:"` | |
HASH=`echo $ENTRY | cut -f 2 -d :` | |
SALT=`echo $HASH | cut -f 3 -d $` | |
RESULT=`openssl passwd -apr1 -salt $SALT $PASSWORD` | |
echo "File: $HTPASSWD" | |
echo "Username: $USERNAME" | |
echo "Entry: $ENTRY" | |
echo "Hash: $HASH" | |
echo "Salt: $SALT" | |
echo "password to check: $PASSWORD" | |
echo "openssl result: $RESULT" | |
if [ $RESULT = $HASH ] | |
then | |
echo "OKAY" | |
else | |
echo "NOT MATCHED" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for writing this! For more security-conscious users, I might suggest prompting the user for the password rather than specifying it on the command line, in order to keep it out of bash_history. Like this: