david/scripts-archive
david
/
scripts-archive
Archived
1
0
Fork 0
This repository has been archived on 2022-04-16. You can view files and clone it, but cannot push or open issues or pull requests.
scripts-archive/htpasswd.sh

31 lines
400 B
Bash
Executable File

#!/bin/bash
function usage {
echo "./htpasswd.sh <username> <file>"
}
if [ $1 ]; then
USER=$1
else
USER=$(whoami)
fi
SUCCESS=1
while [ $SUCCESS -ne 0 ]; do
PASSWD=$(openssl passwd -apr1)
if [ $? -eq 0 ]; then
SUCCESS=0
fi
done
if [ $2 ]; then
FILE=$2
if [ $FILE ]; then
echo "$USER:$PASSWD" >> $FILE
fi
else
echo "$USER:$PASSWD"
fi
exit 0